android - FLAG_ACTIVITY_CLEAR_TOP? -
as title says, why intent.addflags(intent.flag_activity_clear_top)
or intent.setflags(intent.flag_activity_clear_top)
won't work?
i have 3 activities let a, b , c.
when trying launch activity c code:
intent = new intent(this, a.class); i.addflags(intent.flag_activity_clear_top); startactivity(i);
it starts activity doesn't clear top.! -_-
i have tried using setflags()
.
i read different questions on problem, couldn't find right answer. >_<
somebody please help!
edit
code onbackpressed() in activity 'a' requested @codemagic.
@override public void onbackpressed(){ if(wvlogin.cangoback()) wvlogin.goback(); else super.onbackpressed(); }
from documentation flag_activity_clear_top:
if set, and activity being launched running in current task, instead of launching new instance of activity, of other activities on top of closed , intent delivered (now on top) old activity new intent.
as added in comment, activity has been finished before calling b, situation doesn't apply. new instance of activity launched instead.
as see it, have 2 options here:
1) use intent.flag_activity_new_task | intent.flag_activity_clear_task
flags. start activity root of stack. works, other activities in stack lost. assuming first activity (or @ least, not interested in previous activities in task stack) doesn't matter. note: clear_task requires api level 11.
2) possible solution (in case previous assumption not true) not use intent flags @ all:
- b starts c
startactivityforresult()
. - instead of calling a, c finishes, having set result b indicating must launched.
- in
b.afteractivityresult()
, finish b , launch a.
Comments
Post a Comment