Androidアプリケーションを閉じる方法は?


157

アプリケーションを閉じて、バックグラウンドで実行されないようにしたい。

どうやってするか?これはAndroidプラットフォームでの良い習慣ですか?

「戻る」ボタンを使用すると、アプリは閉じますが、バックグラウンドのままです。バックグラウンドでそれらのアプリを殺すためだけに「TaskKiller」と呼ばれるアプリケーションさえあります。



バックグラウンドでもアプリを実行したくないのはなぜですか。
Darpan 2014年

回答:


139

Androidには、ドキュメントに従ってアプリケーションを安全に閉じるメカニズムがあります。終了する最後のアクティビティ(通常、アプリケーションの起動時に最初に表示されるメインのアクティビティ)では、onDestroy()メソッドに数行を配置するだけです。System.runFinalizersOnExit(true)の呼び出しにより、アプリケーションの終了時にすべてのオブジェクトが確実にファイナライズされ、ガベージコレクションが行われます。 必要に応じて、android.os.Process.killProcess(android.os.Process.myPid())を使用してアプリケーションをすばやく強制終了することもできます。これを行う最良の方法は、ヘルパークラスに次のようなメソッドを配置し、アプリを強制終了する必要があるときはいつでもそれを呼び出すことです。たとえば、ルートアクティビティのdestroyメソッドでは(アプリがこのアクティビティを強制終了しないと想定):

また、AndroidはHOMEキーイベントをアプリケーションに通知しないため、HOMEキーが押されたときにアプリケーションを閉じることはできません。Androidは HOMEキーイベントを自分自身に予約するため、開発者はユーザーがアプリケーションを離れることを防止できません。ただしとあなたが判断できHOMEのキーがあることを前提としていヘルパークラスにフラグをtrueに設定することで押されHOMEのキーイベントが表示されていることが発生した場合、その後フラグをfalseに変更し、押されたホームキーは、次に押されていませんでしたアクティビティのonStop()メソッドで押されたHOMEキーを確認します。

メニューおよびメニューによって開始されるアクティビティーで、HOMEキーを処理することを忘れないでください。SEARCHキーについても同様です。以下に、例示するクラスの例をいくつか示します。

アプリケーションが破棄されたときにアプリケーションを強制終了するルートアクティビティの例を次に示します。

package android.example;

/**
 * @author Danny Remington - MacroSolve
 */

public class HomeKey extends CustomActivity {

    public void onDestroy() {
        super.onDestroy();

        /*
         * Kill application when the root activity is killed.
         */
        UIHelper.killApp(true);
    }

}

これを拡張して、それを拡張するすべてのアクティビティのHOMEキーを処理するために拡張できる抽象的なアクティビティを次に示します。

package android.example;

/**
 * @author Danny Remington - MacroSolve
 */

import android.app.Activity;
import android.view.Menu;
import android.view.MenuInflater;

/**
 * Activity that includes custom behavior shared across the application. For
 * example, bringing up a menu with the settings icon when the menu button is
 * pressed by the user and then starting the settings activity when the user
 * clicks on the settings icon.
 */
public abstract class CustomActivity extends Activity {
    public void onStart() {
        super.onStart();

        /*
         * Check if the app was just launched. If the app was just launched then
         * assume that the HOME key will be pressed next unless a navigation
         * event by the user or the app occurs. Otherwise the user or the app
         * navigated to this activity so the HOME key was not pressed.
         */

        UIHelper.checkJustLaunced();
    }

    public void finish() {
        /*
         * This can only invoked by the user or the app finishing the activity
         * by navigating from the activity so the HOME key was not pressed.
         */
        UIHelper.homeKeyPressed = false;
        super.finish();
    }

    public void onStop() {
        super.onStop();

        /*
         * Check if the HOME key was pressed. If the HOME key was pressed then
         * the app will be killed. Otherwise the user or the app is navigating
         * away from this activity so assume that the HOME key will be pressed
         * next unless a navigation event by the user or the app occurs.
         */
        UIHelper.checkHomeKeyPressed(true);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.settings_menu, menu);

        /*
         * Assume that the HOME key will be pressed next unless a navigation
         * event by the user or the app occurs.
         */
        UIHelper.homeKeyPressed = true;

        return true;
    }

    public boolean onSearchRequested() {
        /*
         * Disable the SEARCH key.
         */
        return false;
    }
}

HOMEキーを操作するメニュー画面の例を以下に示します。

/**
 * @author Danny Remington - MacroSolve
 */

package android.example;

import android.os.Bundle;
import android.preference.PreferenceActivity;

/**
 * PreferenceActivity for the settings screen.
 * 
 * @see PreferenceActivity
 * 
 */
public class SettingsScreen extends PreferenceActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.settings_screen);
    }

    public void onStart() {
        super.onStart();

        /*
         * This can only invoked by the user or the app starting the activity by
         * navigating to the activity so the HOME key was not pressed.
         */
        UIHelper.homeKeyPressed = false;
    }

    public void finish() {
        /*
         * This can only invoked by the user or the app finishing the activity
         * by navigating from the activity so the HOME key was not pressed.
         */
        UIHelper.homeKeyPressed = false;
        super.finish();
    }

    public void onStop() {
        super.onStop();

        /*
         * Check if the HOME key was pressed. If the HOME key was pressed then
         * the app will be killed either safely or quickly. Otherwise the user
         * or the app is navigating away from the activity so assume that the
         * HOME key will be pressed next unless a navigation event by the user
         * or the app occurs.
         */
        UIHelper.checkHomeKeyPressed(true);
    }

    public boolean onSearchRequested() {
        /*
         * Disable the SEARCH key.
         */
        return false;
    }

}

アプリ全体でHOMEキーを処理するヘルパークラスの例を次に示します。

package android.example;

/**
 * @author Danny Remington - MacroSolve
 *
 */

/**
 * Helper class to help handling of UI.
 */
public class UIHelper {
    public static boolean homeKeyPressed;
    private static boolean justLaunched = true;

    /**
     * Check if the app was just launched. If the app was just launched then
     * assume that the HOME key will be pressed next unless a navigation event
     * by the user or the app occurs. Otherwise the user or the app navigated to
     * the activity so the HOME key was not pressed.
     */
    public static void checkJustLaunced() {
        if (justLaunched) {
            homeKeyPressed = true;
            justLaunched = false;
        } else {
            homeKeyPressed = false;
        }
    }

    /**
     * Check if the HOME key was pressed. If the HOME key was pressed then the
     * app will be killed either safely or quickly. Otherwise the user or the
     * app is navigating away from the activity so assume that the HOME key will
     * be pressed next unless a navigation event by the user or the app occurs.
     * 
     * @param killSafely
     *            Primitive boolean which indicates whether the app should be
     *            killed safely or quickly when the HOME key is pressed.
     * 
     * @see {@link UIHelper.killApp}
     */
    public static void checkHomeKeyPressed(boolean killSafely) {
        if (homeKeyPressed) {
            killApp(true);
        } else {
            homeKeyPressed = true;
        }
    }

    /**
     * Kill the app either safely or quickly. The app is killed safely by
     * killing the virtual machine that the app runs in after finalizing all
     * {@link Object}s created by the app. The app is killed quickly by abruptly
     * killing the process that the virtual machine that runs the app runs in
     * without finalizing all {@link Object}s created by the app. Whether the
     * app is killed safely or quickly the app will be completely created as a
     * new app in a new virtual machine running in a new process if the user
     * starts the app again.
     * 
     * <P>
     * <B>NOTE:</B> The app will not be killed until all of its threads have
     * closed if it is killed safely.
     * </P>
     * 
     * <P>
     * <B>NOTE:</B> All threads running under the process will be abruptly
     * killed when the app is killed quickly. This can lead to various issues
     * related to threading. For example, if one of those threads was making
     * multiple related changes to the database, then it may have committed some
     * of those changes but not all of those changes when it was abruptly
     * killed.
     * </P>
     * 
     * @param killSafely
     *            Primitive boolean which indicates whether the app should be
     *            killed safely or quickly. If true then the app will be killed
     *            safely. Otherwise it will be killed quickly.
     */
    public static void killApp(boolean killSafely) {
        if (killSafely) {
            /*
             * Notify the system to finalize and collect all objects of the app
             * on exit so that the virtual machine running the app can be killed
             * by the system without causing issues. NOTE: If this is set to
             * true then the virtual machine will not be killed until all of its
             * threads have closed.
             */
            System.runFinalizersOnExit(true);

            /*
             * Force the system to close the app down completely instead of
             * retaining it in the background. The virtual machine that runs the
             * app will be killed. The app will be completely created as a new
             * app in a new virtual machine running in a new process if the user
             * starts the app again.
             */
            System.exit(0);
        } else {
            /*
             * Alternatively the process that runs the virtual machine could be
             * abruptly killed. This is the quickest way to remove the app from
             * the device but it could cause problems since resources will not
             * be finalized first. For example, all threads running under the
             * process will be abruptly killed when the process is abruptly
             * killed. If one of those threads was making multiple related
             * changes to the database, then it may have committed some of those
             * changes but not all of those changes when it was abruptly killed.
             */
            android.os.Process.killProcess(android.os.Process.myPid());
        }

    }
}

1
これは、アプリケーションの一部として実行されているすべてのアクティビティを含む、System.exit(0)を呼び出したアプリケーション全体を強制終了することになっています。他のすべてのアプリケーションは引き続き実行されます。アプリケーション内のすべてのアクティビティではなく、アプリケーション内の1つのアクティビティのみを強制終了する場合は、強制終了するアクティビティのfinish()メソッドを呼び出す必要があります。
ダニーレミントン-OMS

2
このnfoを本当にありがとう。私はAndEngineでゲームを作成していて、finishを呼び出すと、すべてのアクティビティでさえ、Androidは完全にクリーンアップされず、ゲームが再起動されると、GLテクスチャがすべてグリッチアウトされるなど、完全にバグが発生します。調査した結果、AndEngineだと思ったのですが、Androidがプロセスを終了しようとしたときにプロセスを保存しようとしていたため、問題が発生しているのではないかと気付きました。「exitを呼び出すべきではありません。ユーザーエクスペリエンスを台無しにする」というコメントはすべてナンセンスです。アプリケーションは開いたままにする必要があります。天気予報

17
本番アプリケーションではこのコードを使用しないでください。killApp()Googleが予測できない動作を引き起こす可能性があることを示しているため、本番アプリケーションはに示すコードを呼び出す必要はありません。
CommonsWare 2011

1
System.runFinalizersOnExit(true); メソッドは非推奨です。アプリケーションを安全に閉じる別の方法は何ですか(ガベージコレクション)。
Ajeesh 2013年

1
これが最初に投稿された時点では非推奨ではありませんでした。現在のAPは7で、現在のAPIは19であるため、これを行う別の方法がおそらくあります。
ダニーレミントン

68

はい!アプリケーションを閉じることができるので、バックグラウンドで実行されなくなります。他のユーザーがコメントしたようにfinish()、Googleが推奨する方法は、プログラムが終了したことを意味するものではありません。

System.exit(0);

そのようにすると、アプリケーションが閉じてバックグラウンドで何も実行されなくなりますが、これは賢く使用して、ファイルを開いたままにしたり、データベースハンドルを開いたままにしたりしないでください。これらは通常、finish()コマンドによってクリーンアップされます。

アプリケーションで[終了]を選択すると、個人的に嫌いですが、実際には終了しません。


44
System.exit()の使用は絶対にお勧めしません。
CommonsWare、2010年

14
これが推奨される方法ではないことは主張しませんが、アプリケーションがバックグラウンドから即座に終了することを保証するソリューションを提供できますか?そうでなければ、System.exitは、Googleがより良い方法を提供するまでの道です。
Cameron McBride

74
あなたが「想定されていない」と誰が決めるのか、実際には終了しないメソッドを作成した人たちと同じですか?ユーザーがアプリケーションを閉じたくない場合、5番目に人気のある有料アプリはタスクキラーではありません。人々は解放されたメモリを必要とし、コアOSは仕事をしません。
Cameron McBride

19
それは不適切なアドバイスであることに同意しましたが、質問が尋ねた実際の回答を提供するために賛成票を投じました。フォローアップの説明がなく、「本当にやりたくない」と聞いてとてもうんざりしています。Androidは、iPhoneと比較して、これらのタイプのドキュメントに関する絶対的な悪夢です。
DougW 2010

11
Androidでタスクキラーを使用しても、メモリのメリットはありません。Androidは、フォアグラウンドアプリがより多くのメモリを必要とする場合、フォアグラウンドにないすべてのアプリケーションを破棄して一掃します。場合によっては、Androidはタスクキラーで閉じられたアプリを再開します。Androidは、アプリの切り替え時間を短縮するために、最近使用したアプリケーションで不要なメモリをすべて満たします。終了ボタンを使用してアプリを構築しないでください。ANDROIDでタスクマネージャーを使用しないでください。geekfor.me/faq/you-shouldnt-be-using-a-task-killer-with-android android-developers.blogspot.com/2010/04/...
ヤヌシュ

23

これは私がそれをした方法です:

私は置くだけ

Intent intent = new Intent(Main.this, SOMECLASSNAME.class);
Main.this.startActivityForResult(intent, 0);

アクティビティを開くメソッドの内部、次に私が置いたアプリを閉じるように設計されたSOMECLASSNAMEのメソッドの内部:

setResult(0);
finish();

そして、私は私のメインクラスに以下を入れました:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == 0) {
        finish();
    }
}

18

しばらくしてから今すぐ自分の質問に答えてください(CommonsWareが最も一般的な答えについてコメントしているため、これを行うべきではないと言っています)。

アプリを終了したいとき:

  1. 最初のアクティビティ(スプラッシュスクリーン、または現在アクティビティスタックの一番下にあるアクティビティ)をFLAG_ACTIVITY_CLEAR_TOP(それ以降に開始された他のすべてのアクティビティを終了します。つまり、それらすべてを)開始します。このアクティビティをアクティビティスタックに含めるようにしてください(何らかの理由で事前に終了しないでください)。
  2. finish()はこの活動を呼びます

これで十分です。


3
これは実際にはあなたのアプリを殺しません。アプリリストには引き続き表示されます。私はあなたのすべての活動を殺します。
Joris Weimar

1
FLAG_ACTIVITY_CLEAN_TOPは、Sonyスマートフォンでは機能しません。AndroidManifest.xmlでの活動にclearTaskOnLaunch =「true」属性:あなたはアンドロイド追加していることを回避することができます
Rusfearuth

10

このコードをボタンのEXITクリックに書き込んでください。

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("LOGOUT", true);
startActivity(intent);

そして、MainActivity.classonCreate()メソッドで、以下のコードを最初の行として記述します。

if (getIntent().getBooleanExtra("LOGOUT", false))
{
    finish();
}

9

フレームワークAPIを使用することはできません。プロセスをいつ削除するか、メモリに残すかは、オペレーティングシステム(Android)の裁量に任されています。これは効率上の理由によるものです。ユーザーがアプリを再起動することに決めた場合、アプリはメモリに読み込まれなくても、すでにそこにあります。

いいえ、それ推奨されないだけでなく、不可能にすることもできません。


4
Integer z = nullのようなことをいつでも行うことができます。z.intValue(); //最悪の答え
Joe Plante 2012

6
そうだね。電話を壁にぶつけて、十分な圧力が加えられた場合、開いているすべてのアプリケーションを終了することもできます。私はまだそれをお勧めしません。私はそれに応じて私の投稿を更新しました。
Matthias

@JoePlanteは、アプリメニューを開いたときにもアプリをバックグラウンドのままにします。それは不可能のようです。
peresisUser 2015

8

アプリを終了する方法:

方法1:

呼び出しfinish();てオーバーライドしますonDestroy();。次のコードを入れてくださいonDestroy()

System.runFinalizersOnExit(true)

または

android.os.Process.killProcess(android.os.Process.myPid());

方法2:

public void quit() {
    int pid = android.os.Process.myPid();
    android.os.Process.killProcess(pid);
    System.exit(0);
}

方法3:

Quit();

protected void Quit() {
    super.finish();
}

方法4:

Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);

if (getIntent().getBooleanExtra("EXIT", false)) {
     finish();
}

方法5:

呼び出しfinish()は、アプリケーション全体ではなく、現在のアクティビティのみを終了する場合があります。ただし、これには回避策があります。を起動するたびにactivity、を使用して起動しstartActivityForResult()ます。アプリ全体を閉じたいときは、次のようなことができます:

setResult(RESULT_CLOSE_ALL);
finish();

次に、すべてのアクティビティのonActivityResult(...)コールバックを定義activityして、RESULT_CLOSE_ALL値が返されたときに、次の呼び出しも行うようにしますfinish()

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(resultCode){
        case RESULT_CLOSE_ALL:{
            setResult(RESULT_CLOSE_ALL);
            finish();
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

インテントintent = new Intent(getApplicationContext()、LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra( "EXIT"、true); startActivity(intent); とてもうまくいきます。
hitesh141

アクティビティA-> B-> C-> Dを開始しました。アクティビティDIで戻るボタンが押されたとき、アクティビティAに移動します。Aは私の開始点であるため、すでにスタック上にあるため、Aの上にあるすべてのアクティビティがクリアされ、Aから他のアクティビティに戻ることはできません。 。@Override public boolean onKeyDown(int keyCode、KeyEvent event){if(keyCode == KeyEvent.KEYCODE_BACK){Intent a = new Intent(this、A.class); a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(a); trueを返します。} return super.onKeyDown(keyCode、event); }
hitesh141 2015

5

これがWindows Mobileの動作方法です。これはマイクロソフトが問題について言わなければならないことです:

http://blogs.msdn.com/windowsmobile/archive/2006/10/05/The-Emperor-Has-No-Close.aspx(ブログ投稿のタイトルを2006年からずっと覚えていて悲しいですか?私はグーグルで「皇帝は近づいていない」と検索して記事を見つけました笑)

要するに:

アプリがバックグラウンドで動作しているときにシステムがより多くのメモリを必要とする場合、アプリは閉じられます。ただし、システムがより多くのメモリを必要としない場合、アプリはRAMにとどまり、ユーザーが次に必要になったときにすぐに復帰できるようになります。

O'Reillyでのこの質問の多くのコメントは、Androidはほとんど同じように動作し、Androidが使用しているメモリが必要な場合にのみしばらく使用されていないアプリケーションを閉じることを示唆しています。

これは標準機能であるため、動作を強制的に閉じるように変更すると、ユーザーエクスペリエンスが変わります。多くのユーザーはAndroidアプリを穏やかに却下することに慣れているため、他のタスクを実行した後に戻る意図でアプリを却下すると、アプリケーションの状態がリセットされるか、時間がかかることに不満を感じる場合があります。開く。私は標準的な振る舞いに固執するでしょう。


5

アクティビティでfinish()メソッドを呼び出すと、その現在のアクティビティに希望する効果が得られます。


14
いいえ、ありません。アプリケーションではなく、現在のアクティビティを終了します。タスクスタックの一番下のアクティビティをfinish()すると、アプリケーションは終了したように見えますが、Androidは、適切と思われる限り実際にそれを保持することを決定する場合があります。
Matthias

実際、アプリケーションを完全に終了する必要がある場合は、各アクティビティのfinishメソッドを呼び出し、開始した可能性のあるサービスについても考慮する必要があります。私も最初の答えを編集しました-省略してすみません。
r1k0 2010年

3

上記のすべての答えのどれも私のアプリでうまく機能していません

これが私の作業コードです

終了ボタン:

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
ComponentName cn = intent.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
mainIntent.putExtra("close", true);
startActivity(mainIntent);
finish();

そのコードは、他のすべてのアクティビティを閉じて、MainActivityでMainActivityを上に置くことです。

if( getIntent().getBooleanExtra("close", false)){
    finish();
}

2

入れてfinish();以下のように声明を:

myIntent.putExtra("key1", editText2.getText().toString());

finish();

LoginActivity.this.startActivity(myIntent);

すべての活動で。



2

以下のコードをコピーして、AndroidManifest.xmlファイルを最初のアクティビティタグの下に貼り付けます。

<activity                        
            android:name="com.SplashActivity"
            android:clearTaskOnLaunch="true" 
            android:launchMode="singleTask"
            android:excludeFromRecents="true">              
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER"
                />
            </intent-filter>
        </activity>     

また、AndroidManifest.xmlファイルのアクティビティタグの下のすべてに以下のコードを追加します

 android:finishOnTaskLaunch="true"

1

2.3では不可能です。たくさん検索して、たくさんのアプリを試しました。最良の解決策は、(go taskmanager)と(fast reboot)の両方をインストールすることです。それらを一緒に使用すると、機能し、メモリを解放します。別のオプションは、アプリの制御(クローズ)を可能にするアンドロイドアイスサンドイッチ4.0.4にアップグレードすることです。



1

finishAffinity()アプリのすべてのアクティビティを閉じたい場合は、を使用することをお勧めします。Androidドキュメントによると

Finish this activity as well as all activities immediately below it in the current task that have the same affinity.

1
public class CloseAppActivity extends AppCompatActivity
{
    public static final void closeApp(Activity activity)
    {
        Intent intent = new Intent(activity, CloseAppActivity.class);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        finish();
    }
}

そしてマニフェストでは:

<activity
     android:name=".presenter.activity.CloseAppActivity"
     android:noHistory="true"
     android:clearTaskOnLaunch="true"/>

その後、電話をかけることができCloseAppActivity.closeApp(fromActivity)、アプリケーションが閉じられます。


1

onBackPressedに次のコードを記述するだけです。

@Override
public void onBackPressed() {
    // super.onBackPressed();

    //Creating an alert dialog to logout
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage("Do you want to Exit?");
    alertDialogBuilder.setPositiveButton("Yes",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    startActivity(intent);
                }
            });

    alertDialogBuilder.setNegativeButton("No",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {

                }
            });

    //Showing the alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

0

finish();を呼び出すことにより OnClickボタンまたはメニュー

ケースR.id.menu_settings:

      finish();
     return true;

他の回答のコメントに記載されているfinish()ように、アプリを殺すことはありません。以前のインテントに戻るか、アプリのバックグラウンドになる場合があります。
ラプター2014年

0

あなたの活動とそれに関連するすべてのサブ活動が終了すると思います。

public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();]
        if (id == R.id.Exit) {
            this.finishAffinity();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

0

テーブルSystem.exitを使用する最良かつ最短の方法。

System.exit(0);

VMはそれ以上の実行を停止し、プログラムは終了します。


弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.