-5

We are in activity A and we do this following code :

if (previousActivity){  // what method calling the previous activity ?
                        Intent intent = new Intent(
                                LoginActivity.this,
                                CmdEndActivity.class);   // I want to go in CmdEndActivity
                        intent.putExtra("username", user);
                        intent.putExtra("useremail", email);
                        startActivity(intent);
                        finish();

                        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

                    }
                    else {
                        Intent intent = new Intent(
                                LoginActivity.this,
                                Reservation4.class);  // I want to go in Reservation4
                        intent.putExtra("username", user);
                        intent.putExtra("useremail", email);
                        startActivity(intent);
                        finish();

                        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

                    }

Is it possible?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Abdou
  • 1
  • 1

2 Answers2

0

Try this

@Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == android.R.id.home) {
            onBackPressed();
            return true;
        }
        return false;

    }
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
0

You can use putExtra in Intent to pass the activity name to another one. and then at destination activity use getIntent and check if this is equal to Activity 1 or Activity 2. Something like below:

Intent intent = new Intent(this, Activity2.class);
intent.putExtra("activity_name", "Activity 1");
startActivity(intent);

And in Activity 2 check the extra value:

String activity_name = getIntent().getStringExtra("activity_name");
if(activity_name.equal("Activity 1")){
  //... goto Activity B
}else if(activity_name.equal("Activity 2")){
  // ... goto Activity C
}
SadeghAlavizadeh
  • 609
  • 3
  • 17
  • 33