Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android same method called twice

Tags:

java

android

I have a method that runs when the app is opened. It is called from onCreate. But I also call it from onResume. The problem I have is that at the moment it is running twice when the app opens. Is there a way to stop this or a better way to implement what I am trying to achieve?

Thanks

like image 373
Somk Avatar asked Dec 12 '22 08:12

Somk


1 Answers

When an activity starts, onCreate() is called first and then onResume() is called,if you want it to be called only once, remove the call in onCreate().

calling the method in onResume() will ensure that the method is called when the activity regains focus, like after back press etc..

like image 182
Yashwanth Kumar Avatar answered Jan 01 '23 09:01

Yashwanth Kumar