Ahmet Urun Ahmet Urun - 3 months ago 12
Android Question

Does the Intents get killed after i pass to another Intent Android

I'm working on an android application and in the application I have a couple buttons that let user to pass to another activity. Now the way I'm doing the transitions between this Intents is like below:

Intent intent = new Intent(this,user_area.class);
intent.putExtra("user",user_name.getText().toString());
startActivity(intent);


With the above content I start an activity and from that activity I'm getting back to the
MainActivity
using this code:

Intent intent = new Intent(context,MainActivity.class);
startActivity(intent);


But i suspect this cause memory to be over used because I'm not actually getting back to the
Main Activity
that created when application started, I'm just creating another instance of
MainActivity
I guess. Is this really as i thought and if it is how can I get back to the activity that created in the beginning or if I can't do such thing how can I make app to let the previous activity go?

Answer

In your solution you just have to press back button and you'll be back in first activity. If you want to close it and after open new instance like you are doing in second activity just add

finish();

at the end of

Intent intent = new Intent(this,user_area.class);
intent.putExtra("user",user_name.getText().toString());
startActivity(intent);