0

アクティビティとサービスを実行するAndroidアプリを作成しました。

アクティビティのondestroy()関数でサービスを停止しました。

ただし、アプリケーションが閉じられてondestroy()が呼び出された場合でも、プロセスは[設定]->[アプリケーション]->[実行中のサービス]に表示されます。

どうすれば完全に閉じることができますか?

サービスを開始するために使用しているコード:

// initService is called from onCreate() in MainActivity
public void initService() {
    try {
        serviceConnection = new CallService();
        Intent serviceIntent = new Intent();
        serviceIntent.setClassName("com.example.working",
                com.example.working.MyService.class.getName());
        boolean ret = this.bindService(serviceIntent, serviceConnection,
                Context.BIND_AUTO_CREATE);
        Toast.makeText(MainActivity.this, "Service bound : " + ret,
                Toast.LENGTH_SHORT).show();         // Return true or false
    } catch (Exception e) {
        Toast.makeText(this, "initService(): " + e.toString(), Toast.LENGTH_SHORT)
                .show();
    }
}

class CallService implements ServiceConnection {
    @Override
    public void onServiceConnected(ComponentName name, IBinder boundInterface) {
        try {
            Toast.makeText(MainActivity.this, "Service Connected", Toast.LENGTH_SHORT)
                    .show();
            aidlObject = WorkingAidl.Stub.asInterface((IBinder) boundInterface);
        } catch (Exception e) {
            Toast.makeText(MainActivity.this, "onServiceConnected: " + e.toString(),
                    Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onServiceDisconnected(ComponentName paramComponentName) {
        aidlObject = null;
        Toast.makeText(MainActivity.this, "Service Disconnected", Toast.LENGTH_SHORT)
                .show();
    }
}

ありがとう

4

0 に答える 0