Application error when a button is pressed before viewing a pager it loads all the data

I am having a serious problem when I enter my activity and press the "Back" button until the data is fully loaded, I have a view pager inside the action that loads the images. my application crashes and this exception I get:

W / Binder: A RuntimeException is thrown from the middleware stub implementation. java.lang.NullPointerException on android.inputmethodservice.IInputMethodWrapper.setSessionEnabled (IInputMethodWrapper.java:280) in com.android.internal.view.IInputMethod $ Stub.onTransact (IInputMethod.java:12inder) Binder.java:404) at dalvik.system.NativeStart.run (native method)

I am using a broadcast receiver to update ui and I unregister the receiver at onPause().

 updateUIReciver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("refresh"))
                if (viewPager.getAdapter() == null) {
                    VigerAdapter adapter = new VigerAdapter(OpenUrlActivity.this, bitmaps);
                    viewPager.setAdapter(adapter);
                } else
                    viewPager.getAdapter().notifyDataSetChanged();
        }
    };
    registerReceiver(updateUIReciver, filter);'

this is my onPause method

    @Override
protected void onPause() {
    if (updateUIReciver != null)
        unregisterReceiver(updateUIReciver);
    super.onPause();
}

"This is the library I use to upload bitmap images

        new VigerPDF(this)
                .initFromFile(file, new OnResultListener() {
                    @Override
                    public void resultData(Bitmap bitmap) {
                        bitmaps.add(bitmap);
                        try {
                            Intent intent = new Intent();
                            intent.setAction("refresh");
                            OpenUrlActivity.this.sendBroadcast(intent);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void progressData(int i) {
                    }

                    @Override
                    public void failed(Throwable throwable) {
                        throwable.printStackTrace();
                                         }
                });
+4
source share

Source: https://habr.com/ru/post/1694678/


All Articles