1

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!

Luis Aguilar
  • 645
  • 9
  • 26
  • [Please check this link i think it will help you](https://stackoverflow.com/a/29722976/9055402) – Pankaj Meena Nov 27 '18 at 06:07
  • I just tried that but my app just got frozen – Luis Aguilar Nov 27 '18 at 06:13
  • Can you please describe on variable update what exactly you want, there might be other ways then this to achive your result. – Niki Nov 27 '18 at 06:49
  • I have a method that checks the variable value each time the user fails to login with fingerprint. And when it fails for the third the app should hide and show certain imageviews. – Luis Aguilar Nov 27 '18 at 13:51

2 Answers2

1

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

Arthur
  • 769
  • 7
  • 17
0

Do this :

startActivity(getIntent());
finish();

instead of :

finish();
startActivity(getIntent());
Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30