I try to create a custom notification but getting the following exception:
FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification posted from
You cannot put an EditText
into a RemoteViews
. RemoteViews
is limited to a handful of possible widgets, specifically those documented for use on an app widget. And, for a Notification
, I doubt that the AdapterView
options, like ListView
, will work either.
For me, it was because I was setting the text inside the remoteViews TextViews incorrectly. I was doing this:
remoteViews.setString(R.id.txt, "setText", "text");
Using one of these methods solved it for me:
remoteViews.setCharSequence(R.id.txt, "setText", "text");
//Or simply:
remoteViews.setTextViewText(R.id.txt, "text");
I've found that using android:background="?attr/colorPrimaryDark" also causes a crash. When changed to android:background="@color/colorPrimaryDark" it stopped crashing.
If you have a ScrollView amongst your RemoteViews, remove it. This worked for me.
Not all views can be used in RemoteViews. A RemoteViews object can support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
GridLayout
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper
You can't use other layout classes like EditText
or CustomViews.