-2

Is there any way to tell whether an app is back from background(click home button to be background) or back from another activity within the app?

LiangWang
  • 8,038
  • 8
  • 41
  • 54
  • [http://stackoverflow.com/q/4789300/4049612](http://stackoverflow.com/q/4789300/4049612) – Krishna May 05 '16 at 04:55
  • @Jacky what is your exact issue mention your code here other wise there is no way to resolve your issue what you implement in your code and what you exactly wants to do – Amitsharma May 05 '16 at 05:26

1 Answers1

0

In your onCreate callback you can get Intent. This Intent should an extra where have the information about previous Activity.

Here is example:

Suppose ActivityB is loaded from ActivityA and ActivityC. From activityA you can load ActivityB via this way:

Intent intent = new Intent(ActivityA.this, ActivityB.class);
intent.putExtra("FROM_ACTIVITY", "ActivityA");
startActivity(intent);

and if want from ActivityC you can use this:

Intent intent = new Intent(ActivityC.this, ActivityB.class);
intent.putExtra("FROM_ACTIVITY", "ActivityC");
startActivity(intent);

In your ActivityB onCreate method you just use this line:

String fromActivity = getActivity().getIntent().getExtras().getString("FROM_ACTIVITY");

Here, fromActivity Strings contains previous activity information.

That's it :)

Md. Sajedul Karim
  • 6,749
  • 3
  • 61
  • 87