Handling force close [Exception] to stop my native application.

325 views
Skip to first unread message

Anzi

unread,
Jan 27, 2011, 8:48:02 AM1/27/11
to android-ndk
Hi,

My android application internally starting a native
application[exe] as a separate process when it was launched. Problem
is when there is any exception occurred my android application,
android framework killing only my android application. But native
application[exe] runs in background.

Is there any way to handle this in my application to cleanup every
this before android framework kills my application.

Regards
Anzi.

eyal zmora

unread,
Jan 27, 2011, 2:33:21 PM1/27/11
to andro...@googlegroups.com
I have a similar problem. My native code spawns new threads which are not bound to any particular Activity. How can I know when the application teminates (not a particular Activity!), so that I can safely end those threads? 
 
 
Looking around a little, I found this callback method: android.app.Application.onTerminate(), but according to the documentation:
"This method is for use in emulated process environments. It will never be called on a production Android device, where processes are removed by simply killing them"
 
From the 2nd sentence I take it that when an application terminates, its process is killed and therefore any resources that were allocated (new threads, memory allocations...), whether in the Java layer or Native layer, are freed.
Is that a correct assumption?


 
2011/1/27 Anzi <anj...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Dianne Hackborn

unread,
Jan 27, 2011, 2:54:12 PM1/27/11
to andro...@googlegroups.com
These are totally different things.

(1) You should not be forking executables.  Seriously.  We do not currently support this, and you will run into various problems if you do it.  Just please don't do it.

(2) Threads all run in the same process.  When the process goes away, the threads go away.  You don't need to clean them up.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Reply all
Reply to author
Forward
0 new messages