-2

I have an activity. After checking some stuff, I want to go back to previous activity if a previous exists, and if not I want to start a SpecificActivity. How do i do it?

Edited: Seems like no one is understanding what I meant, so let me rephrase. Lets say I am in Activity A. I don't know if A is the only activity in the stack. If there are other activities, then I want to finish A and pop the activity right below A in the stack into the foreground. If A is the only activity in the stack, I want to start some activity Z. How do i do it?

Aayush Karki
  • 781
  • 3
  • 10
  • 25

3 Answers3

2

You have to pass class name as intent extra from both Splash and DashboardActiviy.

In List Activity you have to get the class name using getIntent().

When the user click back button, you need to check the class name based on that you can take decision.

if(name.equalIgnorecase(DashboardActivit.class.getSimpleName()){
  //Add your intent
}else{
  //
}

This may give you definite solution to you.Give a try

1

you can simply override the onBackpress()

  @Override
    public void onBackPressed() {
        super.onBackPressed();
        startActivity(new Intent(this, Destination_Activity.class));
        finish();

    }
raviteja
  • 67
  • 1
  • 13
  • This is not what I asked for and won't work. I have rephrased the question for better understanding. If you could help, that would be nice. – Aayush Karki Nov 08 '17 at 12:59
1

call the next activity like.

Intent intent = new Intent(this,Your_Next_Activity.class);
startActivity(intent);

then it will call your another activity and your current activity will be on background if you will use finish() after calling next activity it will finish your current activity so don't use finish() after calling your next activity in this scenario. After that when you press back button it will automatically finish current activity.

Normal1One
  • 219
  • 3
  • 11
  • This is not what I asked for and won't work. I have rephrased the question for better understanding. If you could help, that would be nice. – Aayush Karki Nov 08 '17 at 13:00