0

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);
}
Vishal Chhodwani
  • 2,567
  • 5
  • 27
  • 40
Julia
  • 1,207
  • 4
  • 29
  • 47
  • I remember Notification class getting depreciated. Can you post code of `Notification` handling as well? – Green goblin May 25 '16 at 13:43
  • Hi, I just posted the remote notification, and the logcat logs where the error is showing. – Julia May 25 '16 at 14:33
  • This sounds like an issue with InstantRun. You could try [turning it off](http://stackoverflow.com/questions/35168753/instant-run-in-android-studio-2-0-how-to-turn-off) to see if it helps. – adelphus May 25 '16 at 14:40
  • That works. Do I need to turn off all the options? I turned all 4 options off, "Enable Instant Run" to hot swap code/resource changes on deploy. Is Instant Run a newly added feature? Will this cause any problem in production when I deploy? – Julia May 25 '16 at 14:48
  • @Julia [InstantRun](http://tools.android.com/tech-docs/instant-run) is a new feature in AS which is why it doesn't work properly. It only applies when you perform incremental debug builds - so it shouldn't affect release builds of your App. – adelphus May 25 '16 at 15:56
  • good, how do I mark your comment as the answer? – Julia May 25 '16 at 16:23
  • Julia, you don't, the right answer has to be a post. – Flummox - don't be evil SE May 26 '16 at 11:06

0 Answers0