6

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)
greeble31
  • 4,894
  • 2
  • 16
  • 30
Strange
  • 1,460
  • 1
  • 7
  • 18
  • Please edit the question to include the stack trace. – greeble31 Oct 18 '19 at 16:56
  • It is not even pointing where the error has occured, and only the activity is getting crashed not the whole application. – Strange Oct 19 '19 at 09:08
  • [This answer](https://stackoverflow.com/a/29314587/6759241) may help. – greeble31 Oct 19 '19 at 13:03
  • what is a dead object actually and what makes an object dead?? the activity is starting and crash is happening only after the click, so the problem is residing somewhere in onclicklisteners. – Strange Oct 19 '19 at 16:17
  • An object is "dead" when the hosting process crashes. You're using this `Intent` for inter-process communication. So, either the web browser or your own app is crashing, which halts the processing of the `Intent`, and produces this error. Sounds like it might be your app. Best to take another look at the logcat, and make sure your app is not experiencing an unhandled exception. – greeble31 Oct 19 '19 at 16:21

1 Answers1

5

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.

Strange
  • 1,460
  • 1
  • 7
  • 18