Luis Aguilar
Luis Aguilar

Reputation: 735

How to Update an activity in Android?

I am trying to update my activity whenever a variable is false inside a method.

I've tried this:

finish();
startActivity(getIntent());

But when I try to start my activity my app just stops and never shows the activity.

I've also tried calling onCreate method but when the variable is false my activity does not updates.

Please help or suggestions!

Upvotes: 1

Views: 2480

Answers (2)

Arthur
Arthur

Reputation: 789

It's very bad practice to recreate activity when any variable changes. If you need to change some values of some variables just make a method that would encapsulate logic of such change or use MutableLiveData class for observing data change. Check this tutorial from Google about LiveData

Upvotes: 1

Abhinav Gupta
Abhinav Gupta

Reputation: 2265

Do this :

startActivity(getIntent());
finish();

instead of :

finish();
startActivity(getIntent());

Upvotes: 0

Related Questions