android - Bad notification posted when using custom view in a layout -


when use custom view in notification's layout, crash remoteserviceexception: bad notification posted package .... here layout:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <com.myapp.views.fontedtextview     android:id="@+id/idas"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:text="test" /> </linearlayout> 

if use textview instead of com.myapp.views.fontedtextview, works fine. note, in normal activity, com.myapp.views.fontedtextview works perfectly.

public class fontedtextview extends textview { public fontedtextview(context context, attributeset attrs, int defstyle) {         super(context, attrs, defstyle);         if(isineditmode()) return;         createfont(); }  public fontedtextview(context context, attributeset attrs) {         super(context, attrs);         if(isineditmode()) return;         createfont(); }  public fontedtextview(context context) {         super(context);         if(isineditmode()) return;         createfont(); }  public void createfont() {     typeface font = typeface.createfromasset(getcontext().getassets(), "lato-regular.ttf");     settypeface(font); } } 

instantiation:

notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service);      remoteviews remoteviews = new remoteviews(context.getpackagename(), r.layout.remotecontrol_notification);     notificationcompat.builder builder = new notificationcompat.builder(context)     .setsmallicon(r.drawable.ic_launcher)     .setcontent(remoteviews)     .setcontentintent(pendingintent.getactivity(context, 0, new intent(context, mainactivity.class), 0));      notificationmanager.notify(100, builder.build()); 


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -