开发者

how to fire an activity from a given activity object

I have saved an object of an activity in a variable. Now i exit from this activity. Then i want that i can use the o开发者_C百科bject of the activity to restart the same activity.

Is it possible to launch an intent of this object of the activity


I am not sure of what you are trying to do I hope this can help.

You can resume resume an left in stack activity by launching an intent for this activity and setting the flag (via intent.setflags method) to FLAG_ACTIVITY_CLEAR_TOP this will clear the top of the current stack and bring back (if it exists) the called activity.

You may also consider using SharedPreferences to save your activity state and then resume it so you can skip heavy tasks or whatever you want.

Anyway as far as i know you shouldn't keep or pass an activity item as it will surely leak:

cf: Android How to avoid memory leak.


Hush is right. You should never save an Activity object somewhere. If you want to restart an Activity dynamically and need to save the Activity that should be restarted somehow you can save the class object of the activity and restart is with.

Class saved = activity.getClass();
startActivity(new Intent(getApplicationContext(), saved);)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜