简体   繁体   English

当调用另一个活动时,Android-完全停止一个活动

[英]Android-Fully stop one activity when another activity is called

I would like to know if there is a way to fully stop one activity when another activity is called. 我想知道是否有一种方法可以在调用另一个活动时完全停止一个活动。 For instance, I have two activities within an application but it seems like that when one activity is called another activity seems to be running (such as Background services). 例如,我在一个应用程序中有两个活动,但是当一个活动被调用时,另一个活动似乎正在运行(例如后台服务)。 I thought that when one activity within an application is called another activity is stopped under the circumstance that there are two activities. 我以为,当一个应用程序中的一个活动被称为另一个活动时,在有两个活动的情况下,该活动就停止了。 Following is manifest file for the application (I deleted lines for Background services here..) Thanks in advance! 以下是该应用程序的清单文件(我在此处删除了后台服务的行..)预先感谢! :) :)

<?xml version="1.0" encoding="utf-8"?>
 <uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">



      <activity
        android:name=".MainActivity"
        android:label="@string/app_name" 
        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="com.me.hello"
        android:label="@string/app_name"
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

        </intent-filter>
    </activity>
        </application>

You can call finish() on the first Activity . 您可以在第一个Activity上调用finish()

Intent intent = new Intent(FirstActivity.class, SecondActivity.class);
startActivity(intent);
finsish();

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

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