简体   繁体   中英

Android onCreate dont call

Need help!

I don't understand why the onCreate method is not always called (it not activity).

If the program is stopped or forcibly stopped from the task manager, then run again in logcat I see that the OnCrete method is called normally.

But if you press the back button (or stop) and then run again, the creative method is no longer called. But at the same time, the creative method of the fragment is called normally, but not in the main class!

How can one be forced, or is there some way, to make oncrete always called up?

public class MyApplication extends MultiDexApplication
{
    ...
    ...

    @Override
    public void onCreate()
    {
        super.onCreate();

        Log.v("CWF","----------------- BEGIN -------------------");
        ...
        ...
    }

    @Override
    public void onTerminate()
    {
    }

    @Override
    public void onLowMemory()
    {
        super.onLowMemory();

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
    }


my manifest

<application
    android:name="com.sample.test.MyApplication"
    android:icon="@mipmap/icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:restoreAnyVersion="true"
    android:usesCleartextTraffic="true">

SYNTAX

@Override
    public void onCreate() {
        super.onCreate();

    }

Question - > I don't understand why the onCreate() method is not always called?

onCreate() called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. Read official guideline aboutApplication class.

Because oncreate called when the activity is first created.

This is lifecycle of activity

onStop() --->onRestart() --->onStart()

For more details refer Activity Life cycle

It's your application instance, not an Activity instance which is shown on the screen. I mean when you move your app to background - app is not killed. It's just in background.

onCreate method is called when application is launching. If you need some another trigger to know when app is on foreground use activities onResume callback method or lifecycle observer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM