开发者

Android access activity1 from activity2

Hi i am new to Android application development.In my Application i have two activity Activity1 and Activity2.From activ开发者_JAVA技巧ity1 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


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.


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.


If from your second activity wants to change something on the previous one, then, instead of using

startActivity(...);

you should use

startActivityForResult(...);

Maybe this link can help.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜