Moving from One Activity to Another Activity in Android

Moving from one activity to another Activity in Android

You haven't defined NextActivity in the AndroidManifest.xml file.

Add these lines in android manifest after</activity> tag. It should work.

<activity
android:name=".NextActivity" >
</activity>

final code will be

<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="Main Activity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NextActivity" >
</activity>
</application>

How to transfer data from one activity to another in android

In the first activity you should put the extra argument to intent like this:

// I assume Page.class is your second activity
Intent intent = new Intent(this, Page.class);
intent.putExtra("arg", getText()); // getText() SHOULD NOT be static!!!
startActivity(intent);

Then in the second activity, you retrieve the argument like this:

String passedArg = getIntent().getExtras().getString("arg");
enteredValue.setText(passedArg);

It's also good to store the arg String in MainActivity as constant and always refer to it in other places.

public static final String ARG_FROM_MAIN = "arg";

How to move from one Activity to another using a button?

put this in oncreate method it will do

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

button1.setOnClickListener(new OnClickListener(){
public void onClick(View arg0)
{ Intent i = new Intent(getApplicationContext(),GoogleDocsLogin.class);
startActivity(i);

} };

android switch from one activity to another

It sounds like you are using setContentView() instead of Intents to switch Activities.

For example, to launch your MenuActivity from your HomeActivity:

Intent menuIntent = new Intent(this, MenuActivity.class);
startActivity(menuIntent);

setContentView() simply changes the display layout; it does not create a new Activity.

How do I transfer data from one activity to another in Android Studio?

Inside Activity2

You can place data inside the Intent directly or you can put them in a Bundle and then put the inside the Intent. Avoid using both for consistency.

  Intent activity3Intent = new Intent(getApplicationContext(), Activity3.class);
//Direct Intent approach
activity3Intent.putExtras("YOUR_STRING_KEY","YOUR_DATA");
//OR Bundle approach
Bundle bundle = new Bundle();
bundle.putString("YOUR_STRING_KEY","YOUR_DATA");
activity3Intent.putExtras(bundle);
startActivity(activity3Intent);

Inside the Activity3 class.

//if direct intent approach
String value = getIntent.getStringExtra("YOUR_STRING_KEY")
//If bundle approach was used.
String value = getIntent().getExtras().getString("YOUR_STRING_KEY");

Moving from one Activity to another in Android, without creating unecessary Activities

After you have executed:

startActivity(new Intent(LoginActivity.this, ProfileActivity.class));

In LoginActivity you can also call finish() to close that activity.

moving from one activity to another in Android

lin.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{

Intent i = new Intent(versionActivity.this, secondActivity.class);
startActivity(i);
finish(); //should use the finish if you need to preserve memory
//other wise don't use it.
}

});

SECOND STEP: AndroidManifest.xml

<activity  android:name=".secondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>


Related Topics



Leave a reply



Submit