0

I have an android application which plays streams from the internet. When there is no stream to play, the app should show a Toast with the message: "Video can't be played" and the screen should be black. When a try these app on a 4.2 Android box everything is alright, but on a 4.4 android box, after the Toast disappears the app crashes. This is the code that shows the Toast:

public void setOnErrorListener(){

        OnErrorListener oel = new OnErrorListener(){

            @Override
            public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
                log.i("TiboVideoView-","error");
                //catchupVideoView.unlockPlayer();

                //Toast.makeText(context,context.getString(R.string.videoerror), Toast.LENGTH_LONG).show();

                nowPlayingDate.setTime(standartTime.getTime());
                nextPlayingDate = null;

                    try {
                        if (isPlaying()) {
                            try {                       
                                stopPlayback(); 
                            } catch (Exception f) {
                            }
                        }
                    } catch (Exception g) {
                    }


                    try{
                    handler.post(LOG_CHANNEL_LOGS);
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }

                try
                {
                Toast.makeText(context,context.getString(R.string.videoerror), Toast.LENGTH_LONG).show();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                return true;
            }

        };

        super.setOnErrorListener(oel);
    }

This is the output from Logcat:

    05-26 10:02:27.316 E/MediaPlayer( 2047): Error (-32,0)
        05-26 10:02:27.316 D/VideoView( 2047): Error: -32,0
        05-26 10:02:27.316 I/hide    ( 2047): 8
        05-26 10:02:27.316 I/TiboVideoView-( 2047): error
        05-26 10:02:27.316 D/AndroidRuntime( 2047): Shutting down VM
        05-26 10:02:27.316 W/dalvikvm( 2047): threadid=1: thread exiting with uncaught exception (group=0x41728ba8)
        05-26 10:02:27.316 E/NotificationService(  516): Package has already posted 50 toasts. Not showing more. Package=com.tibo.webtv
        05-26 10:02:27.316 E/NotificationService(  516): Package has already posted 50 toasts. Not showing more. Package=com.tibo.webtv
        05-26 10:02:27.326 I/Process ( 2047): Sending signal. PID: 2047 SIG: 9
        05-26 10:02:27.326 E/AndroidRuntime( 2047): FATAL EXCEPTION: main
        05-26 10:02:27.326 E/AndroidRuntime( 2047): Process: com.tibo.webtv, PID: 2047
        05-26 10:02:27.326 E/AndroidRuntime( 2047): java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3@42669c68 rejected from java.util.concurrent.ThreadPoolExecutor@4186cfd8[Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 36]
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:590)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at com.tibo.webtv.catchup.am.run(Unknown Source)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.Handler.handleCallback(Handler.java:733)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.Handler.dispatchMessage(Handler.java:95)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.Looper.loop(Looper.java:136)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.app.ActivityThread.main(ActivityThread.java:5017)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.lang.reflect.Method.invokeNative(Native Method)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.lang.reflect.Method.invoke(Method.java:515)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at dalvik.system.NativeStart.main(Native Method)
        05-26 10:02:27.326 W/ActivityManager(  516):   Force finishing activity com.tibo.webtv/.catchup.CatchupActivity
        05-26 10:02:27.426 D/ActivityManager(  516): send app_CRASH broadcast, packageName:com.tibo.webtv
        05-26 10:02:27.426 W/InputDispatcher(  516): channel '41b17380 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
        05-26 10:02:27.426 E/InputDispatcher(  516): channel '41b17380 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
        05-26 10:02:27.426 W/InputDispatcher(  516): channel '41c803b0 Toast (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
        05-26 10:02:27.426 E/InputDispatcher(  516): channel '41c803b0 Toast (server)' ~ Channel is unrecoverably broken and will be disposed!
        05-26 10:02:27.426 W/InputDispatcher(  516): Attempted to unregister already unregistered input channel '41b17380 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity (server)'
        05-26 10:02:27.426 W/InputDispatcher(  516): Attempted to unregister already unregistered input channel '41c803b0 Toast (server)'
        05-26 10:02:27.426 I/ActivityManager(  516): Process com.tibo.webtv (pid 2047) has died.
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41c44f98 u0 com.tibo.webtv/com.tibo.webtv.MainActivity}
        05-26 10:02:27.426 W/ContextImpl(  516): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1162 com.android.server.am.ActivityManagerService.onVideoPlayerCrashed:3700 com.android.server.am.ActivityManagerService.handleAppDiedLocked:3730 com.android.server.am.ActivityManagerService.appDiedLocked:3868 com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied:1046 
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41b17380 u0 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity}
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41c803b0 u0 Toast}
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41beb378 u0 SurfaceView}
        05-26 10:02:27.436 I/ActivityManager(  516): Start proc com.tibo.webtv for activity com.tibo.webtv/.MainActivity: pid=2235 uid=10058 gids={50058, 3003, 1028, 1015}
        05-26 10:02:27.536 D/dalvikvm( 2235): GC_CONCURRENT freed 217K, 26% free 710K/952K, paused 1ms+0ms, total 5ms
        05-26 10:02:27.566 D/dalvikvm(  516): GC_CONCURRENT freed 1407K, 26% free 6296K/8484K, paused 2ms+6ms, total 55ms
        05-26 10:02:27.566 D/dalvikvm(  516): WAIT_FOR_CONCURRENT_GC blocked 38ms
        05-26 10:02:27.586 D/dalvikvm( 2235): GC_CONCURRENT freed 178K, 18% free 948K/1152K, paused 0ms+4ms, total 9ms
        05-26 10:02:27.736 D/dalvikvm( 2235): GC_CONCURRENT freed 192K, 16% free 1149K/1368K, paused 2ms+2ms, total 10ms
        05-26 10:02:27.916 D/dalvikvm(  516): GC_CONCURRENT freed 1350K, 27% free 6276K/8484K, paused 1ms+6ms, total 42ms
        05-26 10:02:27.956 D/dalvikvm( 2235): GC_FOR_ALLOC freed 21K, 11% free 1222K/1368K, paused 4ms, total 4ms
        05-26 10:02:27.966 I/dalvikvm-heap( 2235): Grow heap (frag case) to 10.004MB for 9216016-byte allocation
        05-26 10:02:27.976 D/dalvikvm( 2235): GC_CONCURRENT freed <1K, 2% free 10222K/10372K, paused 0ms+1ms, total 4ms
        05-26 10:02:28.066 D/TextLayoutCache( 2235): Using debug level = 0 - Debug Enabled = 0
        05-26 10:02:28.126 W/Settings( 2235): Setting wifi_sleep_policy has moved from android.provider.Settings.System to android.provider.Settings.Global, value is unchanged.
        05-26 10:02:28.136 W/ActivityThread( 2235): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(ge

tClass().getClassLoader());

Does anybody understand why is this happening?

Maria Agaci
  • 281
  • 2
  • 3
  • 11

2 Answers2

2

Try to see this: Avoiding RejectedExecutionException in Android 4.4 when app uses list. I'm just writing the accepted answer:

The problem lies with the different Executors that AsyncTask uses depending on targetSdkVersion of the app:

1) targetSdkVersion <= 12

AsyncTask.execute() uses the AsyncTask.THREAD_POOL_EXECUTOR. The queue in AsyncTask.THREAD_POOL_EXECUTOR is limited to 128 items. If the queue is full RejectedExecutionException is thrown. This is what happens here

2) targetSdkVersion > 12

AsyncTask uses the AsyncTask.SERIAL_EXECUTOR. AsyncTask.SERIAL_EXECUTOR has an unbounded queue. So in this scenario RejectedExecutionException is never thrown.

Solution 1 (AKA the "clean" solution)

Use a separate APK with targetSdkVersion > 12 and a higher versionCode so that is preferred for HONEYCOMB_MR2 and later versions of Android. This will cause AsyncTask to use ThreadPool.SERIAL_EXECUTOR on HONEYCOMB_MR2 and later version of Android.

Solution 2 (AKA the dirty hack)

Just make AsyncTask.SERIAL_EXECUTOR the default using Reflection.

AsyncTask.class.getMethod("setDefaultExecutor", Executor.class).invoke(null, AsyncTask.SERIAL_EXECUTOR);

Of course i need to see your code to understand how solve your problem.

EDIT. Check that context is not null for first.. by the way, can you post the entire AsyncTask please?

Community
  • 1
  • 1
Atlas91
  • 5,754
  • 17
  • 69
  • 141
0

This: http://developer.android.com/reference/java/util/concurrent/RejectedExecutionException.html says, "Exception thrown by an Executor when a task cannot be accepted for execution."

Additionally I noticed this: Package has already posted 50 toasts. two times. Is the code supposed to show 100 toasts?

You should show some code, too. An exception is always a little bit cryptic.

KJaeg
  • 698
  • 3
  • 7
  • 23