I have two activities named Home and Cart. When I press a button in activity Home it goes to activity Cart.
For that I used the following Code
public void onClick(View v) {
Intent intent = new Intent(this, Cart.class);
startActivity(intent);
}
In Cart activity when I press a button it comes to activity Home.
For That
public void onClick(View v) {
Intent intent = new Intent(this, Home.class);
startActivity(intent);
}
Activities are changing fine but the onCreate method calls every time the activity starts.
Is that a fine life cycle of Activity or not? If not, how can I solve this?
How to solve what? That is the intended behavior of activities. Nevertheless, if you do not want that the methods in your onCreate method are called, you could use a flag like this:
public class YourActivity extends Activity {
private boolean firstStart = true;
public void OnCreate(...) {
if (firstStart) {
//do your stuff here
firstStart = false;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With