简体   繁体   English

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

[英]Android main activity does not launch on start

The main activity does not launch when I open the application; 打开应用程序时,主活动无法启动; I close it by clicking on the home button. 我点击主页按钮关闭它。 When the app starts, it opens on the same page where I was when I clicked the home button. 当应用程序启动时,它会在我单击主页按钮的同一页面上打开。 It somehow remembers the last page I was at, and opens that page instead of the launcher activity. 它以某种方式记住我所在的最后一页,并打开该页面而不是启动器活动。 I added onDestroy() to onPause() on all the activities, but that didn't help either. 我在所有活动上将onDestroy()添加到onPause(),但这也没有帮助。

I am not sure what code to add here, so I'm attaching my AndroidManifest. 我不确定在这里添加什么代码,所以我附加了我的AndroidManifest。 Thanks! 谢谢! Below are the three activities in the 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>

When Home button is pressed, onStop method is called in your activity. 按下Home按钮时,会在您的活动中调用onStop方法。 So what you may do is to add finish(); 所以你可以做的是添加finish(); in onStop method to destroy your activity. onStop方法中销毁你的活动。

Make sure you activity name includes you entire package name instead of example. 确保您的活动名称包含整个包名而不是示例。

Or just replace android:name="example.Activity1" with android:name=".Activity1" 或者用android:name=".Activity1"替换android:name="example.Activity1" android:name=".Activity1"

Your activity is saved on the backstack. 您的活动保存在Backstack上。 Play with the flags passed to the intent when you create your activity. 在创建活动时使用传递给意图的标志 For example, FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET will clear all the activities from this to up the backstack. 例如,FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET将清除从此到Backstack的所有活动。

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

When you close, o exit myintent Activity, when you reopen you app it will clear delete myintent Activity from the backstack and all the activities opened from this activity. 当你关闭时,o退出myintent Activity,当你重新打开app时,它将清除从backstack中删除myintent Activity以及从此活动打开的所有活动。

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

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