Search code examples
androidnotificationscrashremoteview

The app crashes while trying to load notification


06-02 06:43:35.978 4227-4227/? I/art: Late-enabling -Xcheck:jni
06-02 06:43:36.088 4227-4227/meet.projectoklahoma W/System: ClassLoader referenced unknown path: /data/app/meet.projectoklahoma-1/lib/x86
06-02 06:43:36.183 4227-4227/meet.projectoklahoma I/GMPM: App measurement is starting up, version: 8487
06-02 06:43:36.183 4227-4227/meet.projectoklahoma I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
06-02 06:43:36.473 4227-4254/meet.projectoklahoma D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-02 06:43:36.516 4227-4254/meet.projectoklahoma D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
06-02 06:43:36.517 4227-4254/meet.projectoklahoma D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
06-02 06:43:36.532 4227-4254/meet.projectoklahoma D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
06-02 06:43:36.575 4227-4254/meet.projectoklahoma I/OpenGLRenderer: Initialized EGL, version 1.4
06-02 06:43:36.658 4227-4254/meet.projectoklahoma W/EGL_emulation: eglSurfaceAttrib not implemented
06-02 06:43:36.658 4227-4254/meet.projectoklahoma W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xed6fcd40, error=EGL_SUCCESS
06-02 06:44:56.177 4227-4254/meet.projectoklahoma W/EGL_emulation: eglSurfaceAttrib not implemented
06-02 06:44:56.177 4227-4254/meet.projectoklahoma W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xed6ff6c0, error=EGL_SUCCESS
06-02 06:44:56.585 4227-4227/meet.projectoklahoma I/Choreographer: Skipped 30 frames!  The application may be doing too much work on its main thread.
06-02 06:44:57.062 4227-4254/meet.projectoklahoma E/Surface: getSlotFromBufferLocked: unknown buffer: 0xf3dd7240
06-02 06:44:59.933 4227-4227/meet.projectoklahoma D/AndroidRuntime: Shutting down VM
06-02 06:44:59.934 4227-4227/meet.projectoklahoma E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: meet.projectoklahoma, PID: 4227
                                                                    android.app.RemoteServiceException: Bad notification posted from package meet.projectoklahoma: Couldn't expand RemoteViews for: StatusBarNotification(pkg=meet.projectoklahoma user=UserHandle{0} id=1 tag=null score=0 key=0|meet.projectoklahoma|1|null|10060: Notification(pri=0 contentView=meet.projectoklahoma/0x7f04001c vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE))
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

After the user logs in, the app should load notification with the waiting events for him, but it crushes instead. The code above is the error that I get after it crashes.

This is the code in order to send the notification:

private void sendNotification() {
    if (!LocalDataBase.getCurrentUser().getWaitingList().isEmpty())
    {
        int notificationID=1;
        setContentView(R.layout.activity_events_status_bar2);
        TextView eventName=(TextView)findViewById(R.id.incomingEventsNameText2) ;
        Event eventToDisplay=LocalDataBase.getCurrentUser().getWaitingList().get(0);
        eventName.setTag(eventToDisplay);
        Intent showEvents=new Intent(this, EventsStatusBarActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, showEvents, 0);
        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.activity_events_status_bar2);
        contentView.setTextViewText(R.id.incomingEventsNameText2, eventToDisplay.getName());
        contentView.setOnClickPendingIntent(R.id.attendButton,pendingIntent);
        contentView.setOnClickPendingIntent(R.id.declineButton,pendingIntent);
        NotificationCompat.Builder eventsNotification= new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notification_template_icon_bg)
                .setContentText("Incoming notifications")
                .setContent(contentView);
        eventsNotification.setContentIntent(pendingIntent);
        NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationID,eventsNotification.build());
    }


}

This is the code for activity_events_status_bar2:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Event Name"
        android:tag="event"
        android:id="@+id/incomingEventsNameText2"
        android:layout_gravity="left"
        android:textColor="@android:color/black"
        android:textSize="22sp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignBottom="@+id/attendButton" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Going"
        android:id="@+id/attendButton"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/declineButton"
        android:layout_toStartOf="@+id/declineButton"
        android:onClick="selectGoing"/>

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Not Going"
        android:id="@+id/declineButton"
        android:layout_alignBottom="@+id/attendButton"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:onClick="selectNotGoing"/>


</RelativeLayout>

Solution

  • You may have to work around it by applying the contentView directly:

         NotificationCompat.Builder eventsNotification= new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.notification_template_icon_bg)
                        .setContentText("Incoming notifications")
                        .setContent(contentView);
                eventsNotification.setContentIntent(pendingIntent);
     NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    
         Notification myNotification = eventsNotification.build();
         notification.contentView = contentView;
         notificationManager.notify(notificationID,myNotification);