开发者

shutting down android sub activity

I'm trying to implement a sub-activity to play an mp4 movie using MediaPlayer. In trying to finish the activity with setResult and finish inside of onCompletion proved problematic. Then I started searching and searching for examples of closing a sub activity and learned that it must finish from the UI thread.

I simplified the sub activity removing most the media player and moved the finish code into onCreate to at least get it to work from there.

This works:

    // calls onActivityResult, graceful exit, etc
    Log.d("TAG", Thread.currentThread().getName()); // outputs "main"
    signMovieActivity.this.setResult(99);
    signMovieActivity.this.finish(); 

So, how do I do this from onCompletion? The best suggestion I've found so far is to use a handler to do it however this code inside of onCreate works just as poorly as calling finish from the mediaplayer callback:

    Handler handler = new Handler();
    handler.post(new Runnable() {
        public void run() {
        Log.d("TAG", Thread.currentThread().getName()); // outputs "main"
            signMovieActivity.this.setResult(99);
            signMovieActivity.this.finish(); // Full meltdown starting with "I/AndroidRuntime(26581): AndroidRuntime onExit calling exit(0)" 
        }
    });

Please put me back on track!

Here is logcat output when finish() is at the end of onCompletion():

D/movie( 2144): onCompletion called
D/movie( 2144): thread is main
I/FFPlayer( 1169): tm 05460 [InputDemux] Start to wait a/v done 2 2
I/FFPlayer( 1169): tm 00858 [InputDemux] Start to wait a/v done 2 2
I/FFPlayer( 1169): tm 01216 [AudioProc] thread exited
I/FFPlayer( 1169): tm 00902 [InputDemux] Start to wait a/v done 0 2
I/FFPlayer( 1169): tm 300655 [VideoPlay] thread exited
I/FFPlayer( 1169): tm 00473 [VideoProc] thread exited
I/FFPlayer( 1169): tm 03737 [inputDemux] thread exited.
I/FFPlayer( 1169): tm 85592 FFPlayer deleted, mEngine = 0x3c148 this = 0xc860, Count = 0
D/dalvikvm( 2026): GC_EXPLICIT freed 823 objects / 57624 bytes in 55ms
D/dalvikvm( 2037): GC_EXPLICIT freed 618 objects / 42128 bytes in 71ms
<<< finish called here >>>
I/AndroidRuntime( 2144): AndroidRuntime onExit calling exit(0)
I/ActivityManager( 1357): Process com.sign (pid 2144) has died.
I/WindowManagerService( 1357): WIN DEATH: Window{4617dc40 com.sign/com.sign.signActivity paused=false}
I/ActivityManager( 1357): Start proc com.sign for activity com.sign/.signActivity: pid=2165 uid=10126 gids={3003, 1015}
I/WindowManagerService( 1357): WIN DEATH: Window{461a3f90 com.sign/com.sign.signMovieActivity paused=true}
I/WindowManagerService( 1357): 开发者_运维技巧WIN DEATH: Window{460f5a10 SurfaceView paused=false}
<<< entire application restarts >>>


I don't see any problem in calling finish() in the onCompletion() method. I do that myself in a custom video player I made using MediaPlayer, and it works just fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜