简体   繁体   English

从App2启动App1,然后按主屏幕按钮到主屏幕,然后通过按图标再次打开App1,为什么onCreate被调用?

[英]Launch App1 from App2,then press home button to the home screen,and open App1 again by press icon,why onCreate get called?

I launched App1 from App2, and here are the methods in App2: 我从App2启动了App1,这是App2中的方法:

Intent resolveIntent = getPackageManager()
    .getLaunchIntentForPackage("com.example.weijunhao.launchmode");
startActivity(resolveIntent);

Then I press the home button to go to the home screen and I open App2 by pressing the launch icon. 然后,我按下主屏幕按钮转到主屏幕,并通过按下启动图标打开App2。

Why does the onCreate method get called and not the onRestart method? 为什么调用onCreate方法而不调用onRestart方法?

When an Activity is no longer visible (like when you press the home button) it goes to the stopped state. 当“ Activity不再可见时(如按下主屏幕按钮),它将进入停止状态。 From that state it may need to go through the onCreate() method if the system has killed the process to release memory for apps in the foreground (or system processes, I suppose). 从该状态开始,如果系统onCreate()了为前台应用程序(我想是系统进程)释放内存的进程,则可能需要通过onCreate()方法。

There's a nice life-cycle diagram in Android documentation . Android文档中有一个不错的生命周期图。

在此处输入图片说明

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

相关问题 从app1广播到app2 - Broadcast from app1 to app2 Android以编程方式关闭App1并从App1启动App2 - Android Programatically Close Out App1 and Start App2 from App1 应用程序忽略“主页”按钮按下 - App ignoring Home button press Android在App2中使用App1源而不在设备上安装App1 - Android use App1 sources in App2 without installing App1 on device 按下主屏幕按钮,然后通过应用程序图标调用onCreate再次访问应用程序? - pressing home button and access app again from app icon call onCreate? 按下移动主屏幕按钮时重新启动我的应用,然后从最近的最近一个应用按钮开始再次运行 - restart my app when press mobile home button and run again from last recently app button in unity 当两者使用相同的密钥签名时,从App2访问App1的内容提供程序 - Accessing a content provider of App1 from App2 when both are signed with the same key 按主页,然后回到应用程序并按返回按钮,退出应用程序 - press home, then back to app and press back button,it exits the app 我的绘图应用程序运行良好,但是当我想查看我的绘图时,我需要按下主屏幕按钮并再次启动它 - My drawing app runs well, but when I want to see my drawing, I need to press my home button and launch it again 将应用启动图标添加到主屏幕 - Adding app launch icon to the home screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM