Hi i am new to Android application development.In my Application i have two activity Activity1 and Activity2.From activity1 i call Activity2 as Intent.I want to access activity1 from this Activity(activity2) without going to first activity is there any posible way?Pls guide me
-
What do you mean by access. You want to notify Activity1 from Activity2 or you want to access some members of Activity1 from Activity2 ? Please explain what exactly do you want to do. – Mojo Risin Jul 15 '11 at 13:02
-
for example i want to chage the settext() of Edittext (the edittext was in activity1).The edittext was in fristactivity.i want to change it from secound activity. – karthi Jul 15 '11 at 13:11
4 Answers
The only thing which make sence is passing data from Activity 1 to Activity 2. To do it just pass some data through the intent:
intent.putExtra("key", "Your data here");
in second activity:
String data = getIntent().getExtra("key");
If this is not the case, then your task is wrong somewhere. When activity gone background, there is no sence to interact with it.

- 42,730
- 18
- 77
- 103
-
-
1You should not pass instances of objects between activities, even if it would be possible (I don't think it is). – Stefan H Singer Jul 18 '11 at 07:31
No, there isn't. Activity1 might even have been shut down.
If you want to pass DATA between the two activities, that's of course doable. Either by passing data on with the intent, by using http://developer.android.com/reference/android/content/SharedPreferences.html or any other storage you can access from both activities.

- 5,469
- 2
- 25
- 26
So you have the scenario where you start activity B from activity A and you want to change some parameters when activity B is done ( your changes can't be propagated in real time because you can't be sure what is the state of activity A ). So the best way to implement this is to use activity result - for more info about it check Android: Capturing the return of an activity

- 1
- 1

- 8,136
- 5
- 45
- 58