开发者

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

I always heard about to close any activity use finish or use android.os.Process.killProcess(android.os.Process.myPid());开发者_JS百科

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?


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.


First: Well android.os.process.killprocess(pid) is used to kill a process instantly (linux like), and it is a bad idea to use it. It is a good idea to use finish() function but that means that the activity is destroyed but the memory it might not be freed since android will keep it around, in case it has to be restarted.

Second: Use finish() over killProcess

third: if you use killProcess you loose data instantly. You better take care of activity life cycle and let all things run smoothly. You can save data before you use finish() or you can take care of it in onDestroy(), since that function is called to distroy the activity :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜