Arthur
Arthur

Reputation: 35

How to jump from one activity to another particular activity in Android?

I have 3 activities in Android like activity_A,activity_B and activity_C. Calling sequences like this activity_A >>>>>>> activity_B >>>>>> activity_C. Currently I am in activity_C and now I want to jump directly to activity_A without entering into activity_B and I also have to pass some data.

HOW ???? Please give some piece of code for it!!!

Thanks in Advance !!! Arthur

Upvotes: 0

Views: 4209

Answers (4)

user775598
user775598

Reputation: 1323

If you want to add a new copy of Activity_A on top of the stack, just call it the same way as you did before. Otherwise, choose a launch mode depending on what you want the first copy of Activity_A to do. See this question (method #2) for an explanation of passing data between activities.

Upvotes: 1

cornbread ninja
cornbread ninja

Reputation: 427

Specific code will depend on the type of data. But you can do something like this:

Intent i = new Intent(getApplicationContext(), ActivityA.class);
i.putExtra("myData", someData);
startActivity(i);

Upvotes: 0

aromero
aromero

Reputation: 25761

From your ActivityC code:

Intent intent = new Intent(this, ActivityA.class);
intent.putExtra("a key string", data);
startActivity(intent);

In ActivityA you can recover the data using:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    // here use the getters in extras to retrieve the appropiate data type
    // for example if your data is a String the you would call
    // extras.getString("a key string");
}

Upvotes: 0

Haphazard
Haphazard

Reputation: 10948

You can use similar code as you used to get from A>>>B and B>>>C.

Or you can use finish() to exit your Activity. In your case, you'd set a flag in C to tell B to finish then call finish() in C. In B, look for that flag in the onResume() method and finish() B if it exists.

Upvotes: 0

Related Questions