java - Android context choice -


i don't understand context should use in

(mapplicationcontext or context parameter onrecieve method). please, give me explanation context parameter should use , why (i read memory leaks, documentation methods)

final pendingintent pendingintent = pendingintent.getactivity(**mapplicationcontext**, <smth>);  notification.builder notificationbuilder = new notification.builder(                    **mapplicationcontext**).<smth>;  notificationmanager notificationmanager = (notificationmanager) **mapplicationcontext**.getsystemservice(context.notification_service);  // constructor     public downloadertask(mainactivity parentactivity) {         super();          mparentactivity = parentactivity;         mapplicationcontext = parentactivity.getapplicationcontext();      }  mapplicationcontext.sendorderedbroadcast(new intent(                 mainactivity.data_refreshed_action), null,                 new broadcastreceiver() {                      final string failmsg = "download has failed. please retry later.";                     final string successmsg = "download completed successfully.";                      @override                     public void onreceive(context context, intent intent) {                          if (getresultcode() != activity.result_ok) {                              final pendingintent pendingintent = pendingintent                                     .getactivity(mapplicationcontext, <smth>);                              remoteviews mcontentview = new remoteviews(                                     mapplicationcontext.getpackagename(),                                     r.layout.custom_notification);                              if(success){                             mcontentview.settextviewtext(r.id.text,                                     successmsg);                             } else {                                 mcontentview.settextviewtext(r.id.text, failmsg);                             }                              notification.builder notificationbuilder = new notification.builder(                                     mapplicationcontext).<smth>;                             notificationbuilder.setcontentintent(pendingintent);                              notificationmanager notificationmanager = (notificationmanager) mapplicationcontext.getsystemservice(context.notification_service);                             notificationmanager.notify(my_notification_id, notificationbuilder.build());                             log("notification area notification sent");                         }                     }                 }, null, 0, null, null);      } 

always use specific context have. use "this" in activities, , context provided through methods.

leave application context cases can't have access activity context.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -