Skip to content

Instantly share code, notes, and snippets.

@kobeumut
Created August 11, 2017 08:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobeumut/208433352a3b666c4f920377fce125d6 to your computer and use it in GitHub Desktop.
Save kobeumut/208433352a3b666c4f920377fce125d6 to your computer and use it in GitHub Desktop.
This is a common problem, you can not reach the context first and therefore it is null. What you need to do here is that if you use "ActivityName.this" instead of getApplicationContext(), context etc. your problem will be resolved.
/*
This is a common problem, you can not reach the context first and therefore it is null.
What you need to do here is that if you use "ActivityName.this" instead of getApplicationContext(),
context etc. your problem will be resolved.
*/
//For example Alert Dialog;
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); //Activity name
alertDialog.setMessage("Test Messages");
alertDialog.setPositiveButton("OK", listener);
AlertDialog alert = alertDialog.create();
alert.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment