You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: