Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity Closed Throwing DeadObjectException with un-notified error code part

The code is working fine for Devices below API28, it fails for devices Above or Api28. The part of code where error is thrown is not showed by the debugger.

The part where the error is thrown is during intent to a web browser and a video player.

I've tried for all android devices with less than API28 , and the code is working perfectly fine.

    hRecycler.read.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

          //  Toast.makeText(context,url,Toast.LENGTH_SHORT).show();

            Intent i = new Intent(Intent.ACTION_VIEW);

            i.setData(Uri.parse(url));

            context.startActivity(i);
        }
    });

    @Override
    public void onSuccess(VimeoVideo video) {
    String streamlink = (String)video.getStreams().values().toArray()[0];
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
    Uri data = Uri.parse(streamlink);
    intent.setDataAndType(data, "video/mp4");
    context.startActivity(intent);
    }

    @Override
    public void onFailure(Throwable throwable) {
    Toast.makeText(context,"Problem withlink",Toast.LENGTH_SHORT).show();
    }




 RemoteException occurs on reporting focusChanged, w=Window{bd21bfc u0 com.example.android.play_api/com.example.android.play_api.TestimonyActivity EXITING} android.os.DeadObjectException
         android.os.DeadObjectException
     at android.os.BinderProxy.transactNative(Native Method)
     at android.os.BinderProxy.transact(Binder.java:1143)
     at android.view.IWindow$Stub$Proxy.windowFocusChanged(IWindow.java:500)
     at com.android.server.wm.WindowState.reportFocusChangedSerialized(WindowState.java:3903)
     at com.android.server.wm.WindowManagerService$H.handleMessage(WindowManagerService.java:5426)
     at android.os.Handler.dispatchMessage(Handler.java:106)
     at android.os.Looper.loop(Looper.java:214)
     at android.os.HandlerThread.run(HandlerThread.java:65)
     at com.android.server.ServiceThread.run(ServiceThread.java:44)
like image 918
Strange Avatar asked Jun 22 '26 15:06

Strange


1 Answers

The process is being dead, because of the ambiguous context used in the both onClickListener to start activity, while passing the context to the list adapter, in have used getApplicationContext() to pass context to the adapter.

This the problem it could not host the process and killing the activity resulting in crash or DeadObjectException.

Problem in lines:

context.startActivity(intent);
context.startActivity(i);

and context given as getApplicationContext()

Solution:

Change getApplicationContext() to SomeActivity.this

And might be API28 has got its own new rules so, that's why it caused problem in devices with API28 or above.

Hope this helps others.

like image 51
Strange Avatar answered Jun 25 '26 05:06

Strange