0

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

Arthur
  • 25
  • 1
  • 6

4 Answers4

1

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.

Community
  • 1
  • 1
user775598
  • 1,323
  • 9
  • 7
0

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.

Haphazard
  • 10,900
  • 6
  • 43
  • 55
0

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");
}
aromero
  • 25,681
  • 6
  • 57
  • 79
0

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);
cornbread ninja
  • 417
  • 1
  • 6
  • 17
  • I would not recommend the usage of the application context in this situation. It can be unpredictable and lead to leaks of application resources http://developer.android.com/reference/android/content/Context.html#getApplicationContext() – Nick Campion May 31 '11 at 02:08