Stack Exchange
Android context choice
I don't understand which context I should use in 
(mApplicationContext or context parameter from onRecieve method). Please, could you give me some explanation what context parameter I should use and why (I read about memory leaks, documentation for this 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);

    }


speaking generally, if you are in an activity, 'this' is your context ( remember to import android.content.Context; ), you can also pass the context to your fragments.
There are other times when it's a good idea to getApplicationContext, like in services launching alarms and such, but you'd do well to think of the activity you are working with as the context and you'll find out about the other exceptions as you go along.
keeping to this pattern, it is always informative when you think you have access to a context but you realize you don't; consider what exactly you are trying to do with that object, and what part of the program it "belongs" to.
So, inferring what constructed this object, another activity did DownloaderTask(this) or DownloaderTask(this.context) or DownloaderTask(getApplicationContext); I'd do it the first of those ways and just form the constructor here with public void DownloaderTask(Context context) =]

Always use the most specific context that you have. Use "this" in activities, and the context that is provided to you through methods.
Leave the application context to those cases where you can't have access to an activity context.
