Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between finish() and killProcess by myPid();

Tags:

android

I always heard about to close any activity use finish or use android.os.Process.killProcess(android.os.Process.myPid());

first <: i think that what is exact difference between them ?
second <: what is most preferable thing of them?

third <: some time we lose pass data one activity to second when we pass data through intent, so using finish() or killprocess ,data will be lose?

like image 243
Nikunj Patel Avatar asked Sep 02 '11 12:09

Nikunj Patel


1 Answers

first <: i think that what is exact difference between them ?

android.os.Process.killProcess(android.os.Process.myPid()); will kill all the process including all the activities on the stack that you started.

finish will destroy the activity from which you called finish

second <: what is most preferable thing of them?

It depends on what you need, but it is uncommon to killProcess

third <: some time we lose pass data one activity to second when we pass data through intent, so using finish() or killprocess ,data will be lose?

Of course killProcess! killProcess will not return to the previous activity. It will kill all the activities started in this process.

like image 153
Sherif elKhatib Avatar answered Sep 29 '22 23:09

Sherif elKhatib