Android app calls onCreate() when coming from background

activity states in android
fragment lifecycle in android
monitoring state changes in android
android application lifecycle
android save activity state on back button
ondestroy android
onresume android
onsaveinstancestate

I created an Android TV app, on the onCreate() the app handles a lot of data which take it few seconds to load up. When I press the home button and the app goes to background, from my experince the app should come up in the same state as it went to background. for some reason the helps get destroyed and onCreate called again which takes a bit of time to load.

the following logcat apears when the app goes to the background: onDestroy and onRestart both of them aren't called...

EDIT: After adding the permissions, now I get the following logcat:

09-19 16:41:07.938 3456-3456/? E/DataLoader: Exception in onStartLoading() on registering content observer for content uri: content://tvlauncher.mic/farfield_mic_status
    java.lang.SecurityException: Failed to find provider tvlauncher.mic for user 0; expected to find a valid ContentProvider for this authority
        at android.os.Parcel.readException(Parcel.java:1943)
        at android.os.Parcel.readException(Parcel.java:1889)
        at android.content.IContentService$Stub$Proxy.registerContentObserver(IContentService.java:768)
        at android.content.ContentResolver.registerContentObserver(ContentResolver.java:1924)
        at android.content.ContentResolver.registerContentObserver(ContentResolver.java:1913)
        at com.google.android.tvlauncher.data.DataLoader.onStartLoading(DataLoader.java:75)
        at android.content.Loader.startLoading(Loader.java:290)
        at android.app.LoaderManagerImpl$LoaderInfo.start(LoaderManager.java:283)
        at android.app.LoaderManagerImpl.doStart(LoaderManager.java:783)
        at android.app.Fragment.onStart(Fragment.java:1735)
        at com.google.android.tvlauncher.home.HomeFragment.onStart(HomeFragment.java:310)
        at android.app.Fragment.performStart(Fragment.java:2637)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1312)
        at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1549)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1611)
        at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3039)
        at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:2996)
        at android.app.FragmentController.dispatchStart(FragmentController.java:189)
        at android.app.Activity.performStart(Activity.java:6998)
        at android.app.Activity.performRestart(Activity.java:7066)
        at android.app.Activity.performResume(Activity.java:7071)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3620)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3685)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
09-19 16:41:07.949 3456-18708/? E/ActivityThread: Failed to find provider info for tvlauncher.mic

Read your logcat, it requires permission

java.lang.SecurityException: Permission Denial: opening provider com.google.android.katniss.search.serviceapi.KatnissVoiceInteractionContentProvider from ProcessRecord{eed2c2d 2512:com.google.android.tvlauncher/u0a23} (pid=2512, uid=10023)
requires com.google.android.assistant.READ_HOTWORD_STATE or com.google.android.assistant.WRITE_HOTWORD_STATE

Add

<uses-permission android:name="com.google.android.assistant.READ_HOTWORD_STATE" />
<uses-permission android:name="com.google.android.assistant.WRITE_HOTWORD_STATE" />

inside your manifest.xml file

Android app calls onCreate() when coming from background, Android app calls onCreate() when coming from background​​ for some reason the helps get destroyed and onCreate called again which takes a bit of time to load. the following logcat apears when the app goes to the background: onDestroy and onRestart both of them aren't called The order of lifecycle callbacks is well defined, particularly when the two activities are in the same process (app) and one is starting the other. Here's the order of operations that occur when Activity A starts Activity B: Activity A's onPause() method executes. Activity B's onCreate() , onStart(),


Add this permission in your AndroidManifest.xml :

 <uses-permission android:name="com.google.android.assistant.WRITE_HOTWORD_STATE" />

Understand the Activity Lifecycle, I created an Android TV app, on the onCreate() the app handles a lot of data which take it few seconds to load up. When I press the home button and the app  In the Windows 10, open the Your Phone app, tap Android on the right and then tap Continue. 2. Enter your mobile phone number and then tap Send to have Microsoft send you a link that you'll use to


Ok,thanks to: onCreate() called while Activity is stopped (but not destroyed). Only after installation

Adding:

if (!isTaskRoot()) {
  finish();
  return;
} 

to onCreate() solved the problem!

Handle Activity State Changes, In the onCreate() method, you perform basic application startup logic that The onStart() call makes the activity visible to the user, as the app  The app might go to background at any time, so it would be nice if we could get notified instead of having to continually poll the isForeground method. When an application transitions between two Activities there is a brief period during which the first Activity is paused and the second Activity has not yet resumed during this period isForeground will return false, even though our application is the foreground app.


Android: How to detect when App goes background/foreground, When the user switches from app A to app B, the system calls onPause() on app to the background, the system does not call onRestart(), only calling onStart()  OP wrote:I would like to know who really calls the onCreate method in android. I think I recall asking something similar a while ago Anyway, if you're using an IDE like Netbeans or Eclipse, its very easy to see who calls a method. Create a breakpoint, debug the application and have a deek at the call stack.


Android Application Development: Detecting when your app enters , The Lifecycle calls will be,. A.onCreate(); A.onStart() (++activityReferences == 1) (​App enters Foreground); A.onResume(). The Activity  That activity is in the Resumed state, while the app in the other window is in the Paused state. When the user switches from app A to app B, the system calls onPause() on app A, and onResume() on app B. It switches between these two methods each time the user toggles between apps.


Android application and activity life cycle - Tutorial, Step 3: Override the 'onCreate' method in your application class public void onCreate() { When we resume an activity, that means an activity is coming to the screen, and we can store a In order to consume the event of your app moving to the foreground or background, we need methods to call, to handle the logic  After you create your Application class, you need to specify the class in the Android manifest. In the dessertclicker package, create a new Kotlin class called ClickerApplication. To do this, expand app > java and right-click on com.example.android.dessertclicker. Select New > Kotlin File/Class.