The simplest approach that I can think of would be to pass a flag while launching the activity from your own activities. You should also check if the activity was created or resumed, this can be done by setting a boolean in the onCreate method, and then checking it onResume.
Below is the code you can use (not tested):
Activity in which you want to check (say MainActivity.class):
Boolean onCreateCalled = false;
Boolean calledFromAppActivities = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onCreateCalled = true;
Bundle mainData = getIntent().getExtras();
if (mainData != null) {
if (getIntent().hasExtra("call_from_own_activity")) {
calledFromAppActivities = true;
}
}
.....
}
@Override
protected void onResume() {
super.onResume();
if (onCreateCalled && !calledFromAppActivities) {
// The app was not called from any of our activities.
// The activity was not resumed but was created.
// Do Stuff
}
// To stop it from running again when activity is resumed.
onCreateCalled = false;
....
}
When calling MainActivity from other activities, use the code below:
private void call_main () {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("call_from_own_activity", true);
startActivity(i);
}