简体   繁体   English

主屏幕点击事件上的应用程序图标

[英]app icon on click event from home screen

Each time my app icon from home screen is clicked, I want the app to start my FirstActivity.java . 每次单击主屏幕上的应用程序图标时,我都希望该应用程序启动FirstActivity.java The problem now is, say I have navigated through my app and is in the ThirdActivity.java and I have clicked the home Button and go to check out my other apps. 现在的问题是,比如说我浏览了我的应用程序,并且在ThirdActivity.java并且我单击了Home Button并查看了其他应用程序。 Again when I click the app icon in home screen, my Application starts from ThirdActivity.java . 同样,当我单击主屏幕上的应用程序图标时,我的ApplicationThirdActivity.java启动。 I want it to start from FirstActivity.java . 我希望它从FirstActivity.java开始。

I have used clearTaskOnLaunch="true" in manifest for my FirstActivity.java and also checked using android:finishOnTaskLaunch ="true" in all my other activities but the problem is still there. 我已经为我的FirstActivity.java在清单中使用clearTaskOnLaunch="true" ,并且在所有其他活动中也使用android:finishOnTaskLaunch ="true"进行了检查,但问题仍然存在。 How can I solve this? 我该如何解决?

All I have to do was declare android:launchMode="singleTask" in manifest for my FirstActivity.java "only". 我要做的就是在清单中为我的FirstActivity.java“ only”声明android:launchMode =“ singleTask”。 By doing this, every time user selects the app by clicking the app icon in the home screen, app will start with FirstActivity.java 这样,每次用户通过单击主屏幕上的应用程序图标选择应用程序时,该应用程序将以FirstActivity.java启动

Say the user has navigated through my app and is in the ThirdActivity.java and clicked the home Button. 假设用户浏览了我的应用程序,并且位于ThirdActivity.java中,然后单击了主页按钮。 The user has the option of selecting the app again from the background apps section (task manager section). 用户可以选择从后台应用程序部分(任务管理器部分)再次选择该应用程序。 If he/she does so, it will start from where he/she has left (ThirdActivity.java). 如果他/她这样做,它将从他/她离开的地方开始(ThirdActivity.java)。 Only if they click the app icon will the app start from FirstActivity.java 仅当他们单击应用程序图标时,该应用程序才会从FirstActivity.java启动

您需要在启动新活动的意图时完成当前活动,有一种方法可以执行finish();

In your oncreate you just have to start your activity using Intent 在oncreate中,您只需要使用Intent开始活动即可

In manifest you have to provide name attribute to application tag 在清单中,您必须为应用程序标签提供名称属性

<application
        android:allowBackup="true"

        android:icon="@drawable/app_logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 

       android:name=".class name which extends Application"

        >

Here you can see details on how to use application class: http://www.intertech.com/Blog/androids-application-class/ 在这里,您可以查看有关如何使用应用程序类的详细信息: http : //www.intertech.com/Blog/androids-application-class/

http://developer.android.com/reference/android/app/Application.html http://developer.android.com/reference/android/app/Application.html

http://androidexample.com/Global_Variable_Or_Application_Context_Variable_-_Android_Example/index.php?view=article_discription&aid=114&aaid=136 http://androidexample.com/Global_Variable_Or_Application_Context_Variable_-_Android_Example/index.php?view=article_discription&aid=114&aaid=136

You can use this code in onPause() of the second third activity but you have to take care of if onPause() is called because of clicking home button or by any other mean, Code is: 您可以在第二个第三项活动的onPause()中使用此代码,但是必须注意是否由于单击主屏幕按钮或其他任何原因而调用了onPause() ,代码为:

Intent intent = new Intent(AnyActivity.this,FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();

单击主页按钮并启动所需的活动时,可以使用moveTaskToBack(true)

I had resolved the issue by adding all three tags android:launchMode="singleTask" android:clearTaskOnLaunch="true" android:finishOnTaskLaunch ="true" in manifest splash screen activity may be helped some one: 我通过添加清单标记启动屏幕活动中的所有三个标记android:launchMode =“ singleTask” android:clearTaskOnLaunch =“ true” android:finishOnTaskLaunch =“ true”解决了该问题,这可能会有所帮助:

<activity
        android:name=".SplashscreenActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:clearTaskOnLaunch="true"
        android:finishOnTaskLaunch ="true"
        android:screenOrientation="portrait"
        android:theme="@style/AppThemeForAppCompact">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

相关问题 如果应用程序已登录且在后台,然后单击主屏幕上的应用程序启动器图标,它将显示登录屏幕 - if app is login and its in background and click on app launcher icon from home screen it will display login screen 每次单击主屏幕上的应用程序图标时,启动应用程序启动屏幕 - launch a app splash screen everytime we click a app icon from home screen 如何检查活动是从通知启动还是从用户单击 android 中的主屏幕仪表板应用程序图标启动 - how to check whether the activity was launched from notification or from the user click on home screen dashboard app icon in android Android隐藏的应用程序图标出现在主屏幕上 - Android hidden app icon appear on home screen 科尔多瓦android应用程序不显示主屏幕上的图标 - Cordova android app not showing icon on home screen 应用程序图标未显示在应用程序中(在主屏幕上) - App icon does not display in applications (on home screen) 在主(主)屏幕默认设置应用程序图标 - Setting app icon on home(main) screen default 将应用启动图标添加到主屏幕 - Adding app launch icon to the home screen 使用LauncherShortcuts在主屏幕上显示Android App图标 - Android App Icon on Home Screen using LauncherShortcuts Android 主屏幕应用程序图标与不需要的迷你图标徽章 - Android Home Screen App Icon With Unwanted Mini-Icon Badge
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM