在按设备的主页键后,如何始终按图标打开当前活动 [英] How to always open current activity on icon press , after pressing the home key of device

查看:85
本文介绍了在按设备的主页键后,如何始终按图标打开当前活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按下Home键后,我的Activity确实启动了,假设我有三个A,B,C活动并且我禁用了设备上的后按功能.假设A是我的主要启动器活动,并且我从A移至B,从B移至C,然后按Home键,然后再次单击图标,则它总是启动作为启动器的A.但是我不希望那样,当按C上的home键,然后单击图标时,总应以C Activity开头.如果我按B活动上的Home键,则总是想单击图标打开B活动.如何做到这一点.

I really having stuff with the Activity launch after press on home key.Suppose i have three A, B, C activity and i disable the back press on device. Suppose A is my main Launcher Activity and i move from A to B and B to C and pressed the home key and again click on icon then it always start A that is the launcher. But i did not want like that when press home key on C then click on icon should always start with C Activity. If i press home key on B Activity then always want to open B actvity on click of icon. How to make this.

还有一件我不了解的事情,在安装完成时它有两个选项DONE和OPEN.因此,当按下完成"后,可以在当前活动状态下使用home进行按键操作,但是在以OPEN进行启动时,它总是会在任何当前活动按下home键后始终在单击图标的情况下启动启动活动的启动器.

And one more thing i do not understand about the at the time installation complete it have two option DONE and OPEN. So when press on Done it work fine on keypress with home with the current Activity but when start with OPEN then it always start the A Activity that launcher one on click on icon after press home key at any Current Actvity.

该如何解决?谢谢

Manifest.xml文件:

Manifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sunil.apiv2map"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.sendmyposition.A"
            android:configChanges="orientation|keyboardHidden|screenSize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.sendmyposition.B"
            android:configChanges="orientation|keyboardHidden|screenSize" >
        </activity>
        <activity
            android:name="com.example.sendmyposition.C"
            android:configChanges="orientation|keyboardHidden|screenSize" >
        </activity>
    </application>

</manifest>

呼叫活动A到B

   Intent intent = new Intent(A.this, B.class)
            startActivity(intent);
finish()

然后将B呼叫给C

Intent intent = new Intent(B.this, C.class)
            startActivity(intent);

推荐答案

您可以使用

You can use Preferences to do this... Package android.preference provides classes that manage application preferences and implement the preferences UI. Using these ensures that all the preferences within each application are maintained in the same manner and the user experience is consistent with that of the system and other applications.

您可以在SharedPreferences中保存当前的活动名称(字符串),然后在应用程序启动后打开上次打开的活动,然后在MainActivity中读取此字符串.

You can save current Activity name (String) in SharedPreferences, and than read this String in MainActivity after application launch to open last opened activity.

在此处查看 jukas 答案:或者您可以从此处使用此PoC:

Or You can use this PoC from here: How to return to the latest launched activity when re-launching application after pressing HOME?

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
        // Activity was brought to front and not created, 
        // Thus finishing this will get us to the last viewed activity 
        finish(); 
        return; 
    } 

    // Regular activity creation code... 
} 

这篇关于在按设备的主页键后,如何始终按图标打开当前活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆