Tag Archives: context

10,330 views

AlertDialog – MessageBox – Alert – Toast – Android sample

AlertDialog like MessageBox by WinApi: If error: Unable to add window — token null is not for an application try change get Context. // you can put this text into some function body or case in switch statement new AlertDialog.Builder(this) … Continue reading

Posted in Android Examples Code | Tagged , , | Comments Off on AlertDialog – MessageBox – Alert – Toast – Android sample
4,817 views

Alert messagebox toast Android example code

Toast in Android application is equivalent of Alert in JavaScript or MessageBox in WinApi. // Toast android.widget.Toast.makeText(Context context, CharSequence text, int duration) // public static Toast makeText (Context context, CharSequence text, int duration)   Toast.makeText(getApplicationContext(), "Hello world!", Toast.LENGTH_SHORT).show();

Posted in Android Examples Code | Tagged , , , | Comments Off on Alert messagebox toast Android example code
26,297 views

Get Context Java Android example

getContext() getApplicationContext() method Java Android example source   Context myContext_1 = ThisClassName.this; // to open a Dialog Context myContext_2 = getContext(); Context myContext_3 = this.getContext(); Context myContext_4 = this; Context myContext_5 = this.getApplicationContext ();     OnClickListener getImageBtnOnClick = new … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on Get Context Java Android example
10,825 views

Get package name Context-getPackageName Android example

If you often copy your Android project to another you have to using function for obtaining varied information about package. This code show how get package name in Android application as string: Context context = getContext(); // this.getContext(); getApplicationContext(); etc. … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on Get package name Context-getPackageName Android example