finish doesn't appear to be killing the Activity

Put your problem here if it does not fit any of the other categories.

finish doesn't appear to be killing the Activity

Postby amnesia » Thu Mar 05, 2009 7:40 am

I have an application where, when the user clicks a button it the main activity opens a subactivity, via onActivityResult(). Then when the user pushes KeyEvent.KEYCODE_CALL in the subactivity, it calls setResult() and finish(). In the main activity i have onActivityResult() Overriden, all it does is call finish(). At this point, it goes returns to the home screen.

When I run the application again, a blank view comes up, with a title bar and the name of the application in it. it sits there for a while, then pops up a dialog box saying:

Sorry! - Activity FooBar ( in application FooBar ) is not responding. I can click one of two buttons, "Force close" and "Wait".

If I choose "Wait" it waits for awhile and displays the same dialog box periodically.

If I choose "Force close" the activity dies. I can then start the main activity again and it works properly, then repeats this process. It doesn't seem like the orginal Activity is being completely killed. I call the application with startActivity() and get the same result.

Any ideas on what I am doing wrong? I have attached two classes and my manifest.

Thanks.
Attachments
AndroidManifest.xml.txt
(1.04 KiB) Downloaded 168 times
FooMe.java
main activity
(2.44 KiB) Downloaded 192 times
FooIt.java
subactivity
(2.8 KiB) Downloaded 224 times
amnesia
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Feb 26, 2009 6:26 am

Top

Re: finish doesn't appear to be killing the Activity

Postby wilken » Thu Mar 05, 2009 10:58 am

amnesia wrote:I have an application where, when the user clicks a button it the main activity opens a subactivity, via onActivityResult(). Then when the user pushes KeyEvent.KEYCODE_CALL in the subactivity, it calls setResult() and finish(). In the main activity i have onActivityResult() Overriden, all it does is call finish(). At this point, it goes returns to the home screen.

When I run the application again, a blank view comes up, with a title bar and the name of the application in it. it sits there for a while, then pops up a dialog box saying:

Sorry! - Activity FooBar ( in application FooBar ) is not responding. I can click one of two buttons, "Force close" and "Wait".

If I choose "Wait" it waits for awhile and displays the same dialog box periodically.

If I choose "Force close" the activity dies. I can then start the main activity again and it works properly, then repeats this process. It doesn't seem like the orginal Activity is being completely killed. I call the application with startActivity() and get the same result.

Any ideas on what I am doing wrong? I have attached two classes and my manifest.

Thanks.


I'm not sure if this has anything to do with it, but i wouldn't call finish in the launchActivity method. The subactivity is launched asynchronically, so your activity wil be finished before the subactivity finishes (and calls the main activitys onActivityResult method).

perhaps this causes problems?

EDIT: also, you might wat to disable the call to powerUp and unlockPhone in the subactivity to see if the fiddeling with wakelocks and keyguards interferes with anything. if anything this will help you narrwo the problem down.
wilken
Developer
Developer
 
Posts: 35
Joined: Wed Oct 08, 2008 8:22 am

Postby amnesia » Thu Mar 05, 2009 6:21 pm

Thank you for your response. The call to finish() in launchActivity() was put there because i was trying to start the activity with startActivity() to see if it would work, it did not.

Sorry about that, I upped the source in the middle of debugging and didn't think about that.

I will diable the powerUp and unlockPhone and try to see if that shows me more info, thats a good idea.

Thanks again.
amnesia
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Feb 26, 2009 6:26 am

Postby amnesia » Thu Mar 05, 2009 6:33 pm

i comment out the powerUp and the unlock() phone methods and it work as expected. so now i know where the problem is occuring. thanks for the suggestion :)
amnesia
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Feb 26, 2009 6:26 am

Postby wilken » Thu Mar 05, 2009 8:59 pm

amnesia wrote:i comment out the powerUp and the unlock() phone methods and it work as expected. so now i know where the problem is occuring. thanks for the suggestion :)


good bughunting :-)

my instinct tells me you should look at the keyboardguard, since the wakelock code looks like some of the stuff i've got :-)
wilken
Developer
Developer
 
Posts: 35
Joined: Wed Oct 08, 2008 8:22 am

Postby amnesia » Thu Mar 05, 2009 9:31 pm

If I remove the finish() call from the FooIt class, it works fine. I would imagine that when the parent runs finish() it kills all of its children. maybe I need to allow reparenting and call the subactivity with startActivity() and call finish() after startActivity() in the main activity. I will keep exploring.

Thanks again for your replies.
amnesia
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Feb 26, 2009 6:26 am

Top

Postby MrSnowflake » Thu Mar 05, 2009 9:49 pm

Do you know what the actual error message is?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby amnesia » Thu Mar 05, 2009 10:38 pm

I don't get an error message via LogCat. That is why I think it is me not understanding something.

After I start the application again, it brings up the "blank" view/activity and eventually pops the time out message listed above.
amnesia
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Feb 26, 2009 6:26 am

Postby amnesia » Thu Mar 05, 2009 11:26 pm

After looking around a bit more these look like they pertain to my situation:

FooIt.onKeyUp() is where finish() is called in the sub-activity
03-05 14:21:01.069: DEBUG/FooIt.onKeyDown(3695): called with KEYCODE_CALL
03-05 14:21:01.309: DEBUG/FooIt.onKeyUp(3695): called with KEYCODE_CALL

This is me starting the main application after it exited
03-05 14:21:04.589: INFO/ActivityManager(51): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.LAUNCHER} flags=0x10200000 comp={com.foobar/com.foobar.FooMe} }

These look suspect maybe
03-05 14:21:11.497: WARN/ActivityManager(51): Activity destroy timeout for HistoryRecord{43223e10 {com.foobar/com.foobar.FooIt}}
03-05 14:21:14.612: WARN/ActivityManager(51): Launch timeout has expired, giving up wake lock!
03-05 14:21:14.631: WARN/ActivityManager(51): Activity idle timeout for HistoryRecord{432230f8 {com.foobar/com.foobar.FooMe}}
amnesia
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Feb 26, 2009 6:26 am

Postby amnesia » Fri Mar 06, 2009 9:08 am

Thanks for all of the assistance. I have fixed the problem, it seems that the problem was between the keyboard and the chair. :D

it looks like reenableKeyguard() enables KeyguardManager no matter if it was enabled before or not. I thought they were trying to be nice and save me a step. in FooIt.onDestroy() i added:

if( km.inKeyguardRestrictedInputMode() )
{
mKeyguardLock.reenableKeyguard();
}

and that fixed it. I also added this:

if( mWakeLock.isHeld() )
{
mWakeLock.release();
}


I have changed a few other things and attached the working versions if anyone is interested.
Attachments
AndroidManifest.xml.txt
AndroidManifest
(1010 Bytes) Downloaded 203 times
FooMe.java
FooMe.java
(2.34 KiB) Downloaded 215 times
FooIt.java
FooIt.java
(2.21 KiB) Downloaded 274 times
amnesia
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Feb 26, 2009 6:26 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests