0

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">
Serjaru
  • 89
  • 1
  • 9

3 Answers3

1

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 about Application class.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

Because oncreate called when the activity is first created.

This is lifecycle of activity

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

For more details refer Activity Life cycle

sasikumar
  • 12,540
  • 3
  • 28
  • 48
0

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.

Dmytro Batyuk
  • 957
  • 8
  • 15
  • i understand, but it does not activity and does not give me onStart()! – Serjaru May 13 '20 at 13:31
  • So what is the reason you need to know when app starts? Activity callbacks give you results if app is in foreground\background Application is not connected to UI – Dmytro Batyuk May 13 '20 at 14:52