android - How to send a notification when checkbox is checked? -


public class settings extends appcompatactivity {  checkbox cb1;  notificationmanager manager; notification mynotication;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_settings);     cb1=(checkbox) findviewbyid(r.id.notificationchk);       manager = (notificationmanager) getsystemservice(notification_service);// here , above seems ok(no error)      cb1.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {         @override         public void oncheckedchanged(compoundbutton togglebutton, boolean ischecked) {             notificationcompat.builder builder = new notificationcompat.builder(this)//"this" taskstackbuilder cannot applied oncheckedlistener                     .builder(mcontext)//the mcontext not working                     .setcontenttitle("new mail ")                     .setcontenttext("i")                     .setsmallicon(r.drawable.ic_launcher)                     .build();intent resultintent = new intent(this, firstpage.class);//everything inside bracket underlined red         taskstackbuilder stackbuilder = taskstackbuilder.create(this);//"this" taskstackbuilder cannot applied oncheckedlistener          stackbuilder.addparentstack(settings.class);         stackbuilder.addnextintent(resultintent);         pendingintent resultpendingintent =                 stackbuilder.getpendingintent(                         0,                         pendingintent.flag_update_current                 );         mbuilder.setcontentintent(resultpendingintent);//cannot resolve symbol mbuilder          notificationmanager mnotificationmanager =                 (notificationmanager) getsystemservice(context.notification_service);          mnotificationmanager.notify(mid, mbuilder.build());//cannot resolve symbol mid,mbuilder       }//all errors marked   });//basically this,mbuilder,mid,mcontext problem 

i new java , android app deveopement. i've searched internet hours notification , checkbox work , failed. awesome answer:d

change settings.this

remove second builder mcontext.

same inside intent. change settings.this

same taskstackbuilder.create(this) change taskstackbuilder.create(settings.this)

change mbuilder.setcontentintent(resultpendingintent) builder.setcontentintent(resultpendingintent)

change mnotificationmanager.notify(mid, mbuilder.build()) mnotificationmanager.notify(1, builder.build())


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo