如何让启动画面不加载,如果应用程序已经加载到内存

编程入门 行业动态 更新时间:2024-10-09 09:21:58
本文介绍了如何让启动画面不加载,如果应用程序已经加载到内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一些麻烦与spash屏幕。当我启动应用程序,启动画面活动启动几秒钟。后主要活动启动。

如果我preSS home键上的主要活动,然后重新启动的应用程序列表中的应用程序,飞溅活动再次启动,尽管该应用程序已经在backstack。但我预计主要活动从内存中恢复。

如果我preSS后退按钮的机器人之后返回我的主要活动的previous副本。

我有什么做的,使启动画面出现只有一次?而如何从我看到的home键被按下前的最后一个屏幕我的应用程序重新启动?

<活动             机器人:名称=。ui.SplashActivity             机器人:noHistory =真             机器人:screenOrientation =画像             机器人:标签=@字符串/ APP_NAME>         <意向滤光器>             <作用机器人:名称=android.intent.action.MAIN/>             <类机器人:名称=android.intent.category.LAUNCHER/>         &所述; /意图滤光器>     < /活性GT;     <活动机器人:名称=。ui.MainActivity/>

解决方案

这是一个设计问题。您的发射活动不应该是闪屏的活动。相反,在你的主要活动的onCreate方法打开飞溅的活动。这样,如果它被打开新鲜的onCreate被调用,闪屏显示。否则,如果应用程序仅仅是恢复了,它调用onResume,就不会有调用打开启动屏幕的活动。

然后你就可以改变你的清单,以这样的:

<活动         机器人:名称=。ui.MainActivity         机器人:noHistory =真         机器人:screenOrientation =画像         机器人:标签=@字符串/ APP_NAME>     <意向滤光器>         <作用机器人:名称=android.intent.action.MAIN/>         <类机器人:名称=android.intent.category.LAUNCHER/>     &所述; /意图滤光器> < /活性GT; <活动机器人:名称=。ui.SplashActivity/>

I have some troubles with spash screen. When I launch app, splash screen activity launches for some seconds. After it main activity launches.

And if i press home button on the main activity and then relaunch app from apps list, splash activity launches again although the app is already in backstack. But I expect main activity to restore from memory.

And if i press back button after that android returns me to the previous copy of main activity.

What I have to do to make splash screen appear just once? And how to get my app relaunched from the last screen I saw before the home button was clicked?

<activity android:name=".ui.SplashActivity" android:noHistory="true" android:screenOrientation="portrait" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name=".ui.MainActivity"/>

解决方案

This is a design problem. Your launcher activity should not be your splash screen activity. Instead, open your splash activity in your main activity's onCreate method. That way, if it is opened fresh, onCreate is called and the splash screen is shown. Otherwise, if the app is merely resumed, which calls onResume, there would be no call to open the splash screen activity.

Then you can change your manifest to this:

<activity android:name=".ui.MainActivity" android:noHistory="true" android:screenOrientation="portrait" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name=".ui.SplashActivity"/>

更多推荐

如何让启动画面不加载,如果应用程序已经加载到内存

本文发布于:2023-11-13 11:30:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   应用程序   画面   内存

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!