java - Weird behaviour : Activity not getting started again when first started with FLAG_ACTIVITY_NEW_TASK -
my scenario is,
when application starts after user logs in starting activity in following manner,
intent rangefinderscreen = new intent(yourlocationscreen.this, rangefinderscreen.class); rangefinderscreen.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task); startactivity(rangefinderscreen);
i using intent.flag_activity_new_task | intent.flag_activity_clear_task
previous activity stack gets cleared , starts new task.
then have bottom bar navigate between activities, have made common listener (activity) , implemented in activities. looks following,
public class commonlistenerforbottombuttons extends activity implements view.onclicklistener{ context context; string buttonname; public commonlistenerforbottombuttons(context context, string buttonname){ this.context = context; this.buttonname = buttonname; } @override public void onclick(view v) { switch(buttonname){ case "play": intent rangefinder = new intent(context, rangefinderscreen.class); rangefinder.setflags(intent.flag_activity_new_task); context.startactivity(rangefinder); break; // , on more cases } } }
concern
if while starting activity first time following,
intent rangefinderscreen = new intent(yourlocationscreen.this, rangefinderscreen.class); startactivity(rangefinderscreen);
then works.
but if following way (as doing now), i.e. using rangefinderscreen.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task);
then activity doesn't started again.
however if start activity other activity rather common listener activity like,
intent rangefinder = new intent(mygolflerscreen.this, rangefinderscreen.class); startactivity(rangefinder);
then starts.
edit
below how initializing common listener in activities:
homelinearlayout.setonclicklistener(new commonlistenerforbottombuttons(getapplicationcontext(), "home")); playlinearlayout.setonclicklistener(new commonlistenerforbottombuttons(getapplicationcontext(), "play")); weatherlinearlayout.setonclicklistener(new commonlistenerforbottombuttons(getapplicationcontext(), "weather")); messagelinearlayout.setonclicklistener(new commonlistenerforbottombuttons(getapplicationcontext(), "message")); mygolflerlinearlayout.setonclicklistener(new commonlistenerforbottombuttons(getapplicationcontext(), "mygolfer"));
all other activities start except 1 started flag intent.flag_activity_new_task
.
manifest file entry
<activity android:name=".rangefinderscreen" android:label="@string/title_activity_range_finder_screen" android:screenorientation="portrait" > </activity>
if concern manage stacks prefer use "singletop" activities , starting them flag intent.flag_activity_clear_top
manage want do.
you can add launchmode
in manifest inside activity tag equal "singletop"
.
hope works ...
Comments
Post a Comment