android - How to move from one Activity to another after creating the first instance of them? -
i have mainactivity.java
, want open activity a
.
assuming i'm opening activity
a
mainactivity
, i'll use code :
intent = new intent(this,a.class); startactivity(i);
when i'm in activity a, , press button. button finish activity a , go mainactivity. if relaunch activity a, relaunched beginning. not want. want single instance created activity a if move a mainactivity many times want , not relaunched, keep last state.
when mainactiivty starts another, new activity ,activity pushed on top of stack , takes focus. the previous activity remains in stack, stopped. when activity stops, system retains current state of user interface.
when user presses button, current activity popped top of stack (the activity destroyed) , previous activity resumes (the previous state of ui restored). activities in stack never rearranged, pushed , popped stack—pushed onto stack when started current activity , popped off when user leaves using button. such, stack operates "last in, first out" object structure.
note : multiple tasks can held in background @ once. however, if user running many background tasks @ same time, system might begin destroying background activities in order recover memory, causing activity states lost.
in mainactivity activity , press button , activity paopped form stack , destroyed.
again mainactivty navigate a, activity recreated since destroyed. how works.
for more details have @ stack in following link.
http://developer.android.com/guide/components/tasks-and-back-stack.html
android:launchmode
an instruction on how activity should launched. there 4 modes work in conjunction activity flags (flag_activity_* constants) in intent objects determine should happen when activity called upon handle intent.
they are:
- standard
- singletop
- singletask
- singleinstance
http://developer.android.com/guide/topics/manifest/activity-element.html#lmode.
but once activity destroyed , need navigate activity, activity recreated.
Comments
Post a Comment