简体   繁体   English

按下图标时可以启动Android应用吗?

[英]Android app can be launched when press icon?

I've build my project as .apk file and then I installed it into my device. 我将项目构建为.apk文件,然后将其安装到设备中。 My step is: 我的步骤是:

1) Press an icon in app drawer, the Main Activity was started. 1)按应用程序抽屉中的图标,开始“主活动”。

2) Press some action to go to Second Activity 2)按一些动作进入第二活动

3) Press Home Button 3)按主页按钮

4) Press icon again 4)再按一次图标

My expectation is the Second Activity should be resume but it just relaunch Main Activity. 我的期望是第二个活动应该恢复,但它只是重新启动了主要活动。

How can I fix that I have tried set LaunchMode as 如何解决我尝试将LaunchMode设置为的问题

android:launchMode="singleTask" android:launchMode =“ singleTask”

android:launchMode="singleTop" android:launchMode =“ singleTop”

but it doesn't work. 但这不起作用。

Here is my setting in Manifest.xml file 这是我在Manifest.xml文件中的设置

            <activity
        android:name=".auction.MySplashScreen"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
            </activity>

从清单文件中查找,您的问题归结于您设置的android:launchMode属性。您应该将其设置为默认值,或者也可以避免设置它。使用这种方式,您可以获得所需的行为。

In manifest file if you have declared any activity with intent filter having action main and category launcher then that is known to be your first activity or main activity to start your application. 在清单文件中,如果您使用意图过滤器声明了具有活动主体和类别启动器的任何活动,那么这就是您启动应用程序的第一个活动或主要活动。

Now in any android smart phone application starts from two way. 现在在任何android智能手机应用程序中都从两种方式开始。

1) Home screen/Launcher screen 1)主画面/启动画面
Behavior : Now if you press any icon over here then the launcher would see the manifest file of the application and look for the activity having the intent action launcher and main then it will call that activity. 行为:现在,如果您在此处按下任何图标,启动器将看到应用程序的清单文件,并查找具有意图动作启动器和main的活动,然后它将调用该活动。

2) Recent Apps/Long press home button 2)最近使用的应用/长按主屏幕按钮
Behavior : Any recent app that you have opened will be shown here and the Android will have the all the track record of the app and when you press any icon the app will be shown with the latest activity you browsed 行为:您最近打开过的任何应用都会显示在此处,Android会拥有该应用的所有跟踪记录,当您按任意图标时,该应用将显示您浏览过的最新活动


So the behavior you are having is the default behavior and there is not any error/glitch in that. 因此,您所拥有的行为是默认行为,并且其中没有任何错误/故障。 That's the way it should be. 那就是应该的样子。


Solution to your problem : 解决问题的方法:

If you want to show your splash screen only once in application life time then you need to have some Boolean and store it in sharedprefrences and use it to check weather you are first time or not..if its not first time then directly call the next activity using intent. 如果您只希望在应用程序生命周期中仅显示一次启动屏幕,则需要使用一些布尔值并将其存储在共享偏好中,并使用它来检查您是否是第一次天气。如果不是第一次,则直接调用下一个使用意图进行活动。

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

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