What is the difference between starting ActivityB from ActivityA using
1. startActivity(this, ActivityB.class);
versus
2. startActivity(getApplicationContext(), ActivityB.class);
I typically see 1. used more often in examples, but I haven’t come across a reason for why this is the case.
Reference to Activity as a Context (
this) might become obsolete if your Activity goes through configuration changes, like rotation, and is destroyed and created again. Context recieved bygetApplicationContext(), however, persists through lifetime of the process.However, It seems to me it only is an issue when you bind Activity to Service or other similar scenario, so it’s safe to use
thiswhen you use it in intent to start another Activity.