Issue
Let me explain what i want to accomplish. I have SignUp Activity, Login Activity and Main Activity. Sign up activity is parent of login activity means user can go back to it if they press back softkey. and once i go from signup to main activity i clear all alive activity instance
- From Login Activity user can go to sign up activity
- From Signup Activity User can either skip sign up and go to guest mode in main activity or go back to login activity that is its parent activity in manifest
- From main activity user can go to signup activity
now my concern is if i go from sign up to guest mode in main activity [note that login activity instance will be cleared] and then click back register/sign up activity. i want to know if its coming from parent activity i.e. login activity or from main activity.
Solution
You can simply put an extra to your Intent:
Intent intent = new Intent(CallingActivity.this, ActivityToStart.class);
intent.putExtra("startedFrom", CallingActivity.class.toString());
startActivity(intent);
Make the appropriate checks in the newly started Activity:
if(getIntent().getExtras().getString("startedFrom", null) != null) {
//You were started from the specified Activity
}
If you are starting the Activity with startActivityForResult() you can skip the steps above and just use getCallingActivity()
Answered By - Ognian Gloushkov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.