2

I am opening a link in my app and once back is pressed I want to show HomePage to retain user for some more time. I have been trying to acheive this but unable to do so. I get homeLauncher activity as my top as well as baseActivity.

DeepLink Tap > Open desired Activity > user presses back button > Check if its last activity but not homeActivity > If yes, Navigate user to homeActivity.

Tried following code:

@Override
public void onBackPressed() {
ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE );
List<ActivityManager.RunningTaskInfo> taskList = mngr.getRunningTasks(10);

if(taskList.get(0).numActivities == 1 && taskList.get(0).topActivity.getClassName().equals(this.getClass().getName())){
  //// This is last activity
}
else{
    //// There are more activities in stack
}

super.onBackPressed();
}

Android Studio evaluation

I have also tried isTaskRoot but result is same. It doesn't give right answer.Please help

user1288005
  • 890
  • 2
  • 16
  • 36
  • I like your question formatting but your question is not clear may be show as the flow of activities and wht you want to achieve – dsharew Nov 13 '15 at 07:14
  • @DegenSharew I want to show my app's homeActivity when user comes to my app from a deeplink and press back button DeepLink Tap > Open desired Activity > user presses back button > Check if its last activity but not homeActivity > If yes, Navigate user to homeActivity. – user1288005 Nov 13 '15 at 07:17
  • What is the last activity the user was on before leaving to deeplink? – dsharew Nov 13 '15 at 07:18
  • I killed my app before tapping on link. So activity opened from deepLink will be first activity. – user1288005 Nov 13 '15 at 07:22
  • override "onBackPressed()", see [this SO question](http://stackoverflow.com/questions/18337536/android-overriding-onbackpressed) – Bö macht Blau Nov 13 '15 at 07:24
  • Above code is in onBackPressed(). Changed my question above to reflect back the same. – user1288005 Nov 13 '15 at 07:25

0 Answers0