How to kill the process?

I have two actions, the first action is launched by Launcher, the second - by the first. When I kill a process from the first activity, the process is killed. But when I kill him because of the second action, the system will immediately start a new process and the first action. (Changed the PID of the process.) How can I do this cleanly?

I tried 3 different ways to kill the process: System.exit (0), android.os.Process.killProcess (pid) and non-programmatically from the Eclipse Devices panel.

Below are two of the simplest things in the world that I experimented with. Both are external classes in their respective files.

public class FirstActivity extends Activity  {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ((Button)findViewById(R.id.button)).setOnClickListener(
            new OnClickListener() {
                public void onClick(View v) {
                    startActivity(new Intent(FirstActivity.this, 
                        SecondActivity.class));
        }});
    }
}

public class SecondActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_2);
        ((Button)findViewById(R.id.button)).setOnClickListener( 
            new OnClickListener() {
                public void onClick(View v) {
                    // Method 1
                    int pid = android.os.Process.myPid();
                    android.os.Process.killProcess(pid);
                    // Method 2
                    System.exit(0);
        }});
    }
}

( , , , . , . )

+3
4

this.finish()

, Android, , , .

, , . , , / .

, , - - , , ?

+6

. , ( ),

startActivity(new Intent(FirstActivity.this,SecondActivity.class));

.

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);

, .

,

.

, Activity.

, .

+2

I had this problem while I'm new to Android. I created two actions and switched from one layout to anther layout, but when I killed the process of the second activity, the first action will be resume (); and the first layout will be displayed.

the answer to your question: in the first resumption of activity you need to call finish (); the on method in the onResume () method.

0
source

System.exit (0); with this, the entire current process will be killed

0
source

All Articles