Android the same method is called twice

I have a method that starts when the application opens. It is called from onCreate. But I also call it from onResume. The problem is that at the moment it runs twice when the application opens. Is there a way to stop this or the best way to realize what I'm trying to achieve?

thanks

+4
source share
3 answers

When the action begins, onCreate() is called first, and then onResume() is onResume() , if you want it to be called only once, delete the call in onCreate() .

calling the method in onResume () ensures that the method is called when activity regains focus, for example, after a backpressure, etc.

+13
source

Why not use it only in onResume ()? In any case, it is called after creation.

namely http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

0
source

Actions Life Cycle Actions:

Want to get started?

Start of action => onCreate () => onStart () => onResume () => Activity works

Want to close it?

Launch => onPause () => onStop () => onDestroy () => Activity is finally turned off.

I recommend that you read this official documentation article: Activity

0
source

Source: https://habr.com/ru/post/1381098/


All Articles