Home > Uncategorized > How to move from one activity to another

How to move from one activity to another

1.Create a project with HelloShiva and name the activity as HelloShivActivity
2 Create another activity SecondActivityactivity
3. create two xml file say mail.xml and second.xml file
4. create another acvity SimpleJavaAcvity to move from second activity.
5. create another xml file say simplejava.xml
6. run application

package com.rakesh.hello;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class HelloShivActivity extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Intent secondIntent = new Intent(HelloShivaActivity.this,
SecondActivity.class);
startActivity(secondIntent);

}
});

}
}

2.
package com.rakesh.hello;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SecondActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);

Button button = (Button) findViewById(R.id.button2);

button.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Intent secondIntent = new Intent(SecondActivity.this,
SimpleJavaAcvity.class);
startActivity(secondIntent);

}
});

}
}

3. main.xml file

4. second.xml file

5. add second activity into manifest file

6.

package com.rakesh.hello;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SimpleJavaAcvityextends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simplejava);

}
}

7. simplejava.xml file

Now run you application.

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: