简体   繁体   English

Android onCreate 不要调用

[英]Android onCreate dont call

Need help!需要帮忙!

I don't understand why the onCreate method is not always called (it not activity).我不明白为什么不总是调用 onCreate 方法(它不是活动)。

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.如果程序从任务管理器中停止或强制停止,然后在logcat中再次运行我看到正常调用了OnCrete方法。

But if you press the back button (or stop) and then run again, the creative method is no longer called.但是如果你按下后退按钮(或停止)然后再次运行,则不再调用 creative 方法。 But at the same time, the creative method of the fragment is called normally, but not in the main class!但同时,fragment的creative方法是正常调用的,但不是在主类中!

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() 方法?

onCreate() called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. onCreate()在应用程序启动时调用,在创建任何活动、服务或接收器对象(不包括内容提供者)之前。 Read official guideline aboutApplication class.阅读有关Application class 的官方指南。

Because oncreate called when the activity is first created.因为 oncreate 在首次创建活动时调用。

This is lifecycle of activity这是活动的生命周期

onStop() --->onRestart() --->onStart() 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.这是您的应用程序实例,而不是屏幕上显示的 Activity 实例。 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. onCreate方法在应用程序启动时被调用。 If you need some another trigger to know when app is on foreground use activities onResume callback method or lifecycle observer .如果您需要其他触发器来了解应用程序何时处于前台,请使用活动onResume回调方法生命周期观察者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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