Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException: Method call should happen from the main thread #87

Open
Shajeel-Afzal opened this issue Feb 19, 2018 · 0 comments

Comments

@Shajeel-Afzal
Copy link

I am trying the following code to show Custom Notification but the app is crashing giving java.lang.IllegalStateException: Method call should happen from the main thread.

PendingIntent pendingIntent;
        String url = data.get(CommonConsts.NOTIFICATION_KEY_URL);
        String thumbUrl = data.get(CommonConsts.THUMB_URL_KEY);

        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

        // Use TaskStackBuilder to build the back stack and get the PendingIntent
        pendingIntent =
                TaskStackBuilder.create(this)
                        // add all of DetailsActivity's parents to the stack,
                        // followed by DetailsActivity itself
                        .addNextIntentWithParentStack(browserIntent)
                        .getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);

        Custom mLoad = null;
        if (pendingIntent != null) {
            mLoad = PugNotification.with(getBaseContext()).load()
                    .smallIcon(R.mipmap.ic_launcher)
                    .autoCancel(true)
                    .largeIcon(R.mipmap.ic_launcher)
                    .title(title == null ? this.getString(R.string.app_name) +
                            " Alert" : title)
                    .message(messageBody)
                    .bigTextStyle(messageBody, messageBody)
                    .priority(Notification.PRIORITY_MAX)
                    .flags(Notification.DEFAULT_ALL)
                    .when(1)
                    .button(R.drawable.ic_chrome_reader_mode_black_18dp, getString(R.string.read_more), pendingIntent)
                    .click(pendingIntent)
                    .custom()
                    .setImageLoader(new ImageLoader() {
                        @Override
                        public void load(String uri, OnImageLoadingCompleted onCompleted) {
                            viewTarget = getViewTarget(onCompleted);
                            Picasso.with(getBaseContext()).load(uri).into(viewTarget);
                        }

                        @Override
                        public void load(int imageResId, OnImageLoadingCompleted onCompleted) {

                        }
                    })
                    .setPlaceholder(R.drawable.pugnotification_ic_placeholder)
                    .background(thumbUrl);
        }

        if (mLoad != null) {
            mLoad.build();
        }
Complete Exception:
Process: psl99.com.pakistan_super_league, PID: 19021
java.lang.IllegalStateException: Method call should happen from the main thread. at br.com.goncalves.pugnotification.notification.Custom.build(Custom.java:119) at psl99.com.pakistan_super_league.services.MyFirebaseMessagingService.showNewsArticleNotification(MyFirebaseMessagingService.java:276) at psl99.com.pakistan_super_league.services.MyFirebaseMessagingService.sendNotification(MyFirebaseMessagingService.java:150)
atpsl99.com.pakistan_super_league.services.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:111)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(Unknown Source)
at com.google.firebase.iid.zzc.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant