Android主要活动在启动时无法启动

时间:2014-03-21 13:38:56

标签: android android-activity launch

打开应用程序时,主活动无法启动;我点击主页按钮关闭它。当应用程序启动时,它会在我单击主页按钮的同一页面上打开。它以某种方式记住我所在的最后一页,并打开该页面而不是启动器活动。我在所有活动上将onDestroy()添加到onPause(),但这也没有帮助。

我不确定在这里添加什么代码,所以我附加了我的AndroidManifest。谢谢!以下是AndroidManifest中的三项活动。

  <activity android:name="example.Activity1" android:label="MyApp" 
        android:configChanges="orientation" android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>



    <activity
        android:name="example.Activity2"
        android:configChanges="orientation"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="example.Activity3"
        android:configChanges="orientation"
        android:screenOrientation="portrait" >
    </activity>

3 个答案:

答案 0 :(得分:3)

按下主页按钮时,会在您的活动中调用 onStop 方法。因此,您可以在 onStop 方法中添加finish();来销毁您的活动。

答案 1 :(得分:0)

确保您的活动名称包含整个包名而不是示例。

或者只需将android:name="example.Activity1"替换为android:name=".Activity1"

答案 2 :(得分:0)

您的活动保存在Backstack上。在创建活动时,使用传递给意图的flags进行游戏。例如,FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET将清除从此到后台堆栈的所有活动。

Intent myIntent = new Intent(this, MyActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(myintent);

当你关闭时,o退出myintent Activity,当你重新打开app时,它会清除从backstack中删除myintent Activity以及从这个活动中打开的所有活动。