java - intent flag over intent startActivity(i); -


   @override                 public void onclick(view view) {                     // launching news feed screen                     intent = new intent(getapplicationcontext(), profile.class);                     startactivity(i);                 }             }); 

what difference of using code , difference on program compared doe

intent = new intent(currentactivityname.this, nextactivityname.class); i.setflags(intent.flag_activity_reorder_to_front); startactivity(i); 

first 1 uses getapplicationcontext() launch intent. application context attached application's life-cycle , same throughout life of application. if using toast, can use application context or activity context (both) because toast can raised anywhere in application , not attached window.

second 1 uses activity context. activity context attached activity's life-cycle , can destroyed if activity's ondestroy raised. if want launch new activity, must need use activity's context in intent new launching activity connected current activity (in terms of activity stack).

so, whenever need manipulate views go activity-context, else application-context enough.

source: this answer @ difference , when use getapplication(), getapplicationcontext(), getbasecontext() , someclass.this question.

also, reading of above links help:

what's difference between various methods context?

getapplicationcontext(), getbasecontext(), getapplication(), getparent()


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -