I have a music player that used to run fine. However, now after the upgrade, every time I add a simple item to a layout such as the following. The application would crash when I try to play a song. I have to clean project and re run, and it will work. After rerun, and I delete the code, and it will crash again when I tried to play. I then need to clean project again for it to work again.
<Button android:id="@+id/btnTest"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="This is a test"
android:layout_marginLeft="15dp"
android:layout_below="@+id/btnTest2"
/>
I tried sync with gradle files and it doesn't work. The error I'm getting is
FATAL EXCEPTION: main Process: com.musicplayer, PID: 30487 android.app.RemoteServiceException: Bad notification posted from package com.musicplayer: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.musicplayer user=UserHandle{0} id=11 tag=null score=0 key=0|com.musicplayer|11|null|10506: Notification(pri=0 contentView=com.musicplayer/0x7f040039 vibrate=null sound=null defaults=0x20 flags=0x2 color=0x00000000 vis=PRIVATE)) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1466) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Here's my remote notification method
public void showNotification() {
PendingIntent pendingIntent;
Intent intent;
notificationView.setTextViewText(R.id.notify_song_name, mListSongs.get(SONG_POS).getSongName());
intent = new Intent(ACTION_STOP);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_STOP, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_stop, pendingIntent);
intent = new Intent(ACTION_PREVIOUS);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_PREVIOUS, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_previous, pendingIntent);
intent = new Intent(ACTION_NEXT);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_NEXT, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_next, pendingIntent);
intent = new Intent(ACTION_PAUSE);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_PAUSE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_pause, pendingIntent);
intent = new Intent(ACTION_PLAY);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_PLAY, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_play, pendingIntent);
intent = new Intent(this, MusicPlayerActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
pendingIntent = PendingIntent.getActivity(this, 0,intent, 0);
mNotification = notificationBuilder
.setSmallIcon(R.drawable.app_icon).setOngoing(true)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setContent(notificationView)
.setDefaults(Notification.FLAG_NO_CLEAR)
.build();
notificationManager.notify(NOTIFICATION_ID, mNotification);
}