This article mainly collects some problems encountered by individuals during Android Application Development, including how to solve some bugs encountered during development, or how to call a method through code to implement certain functions ..... and other issues. As the saying goes: Good memory is worse than bad writing.
[1] How to click the Button in Android to implement the BACK (return) function:
There are many people on the Internet who say that by calling:
[Html]
OnKeyDown (KeyEvent. KEYCODE_BACK, null );
To implement this function. However, an error is reported !!
You can call the following system methods to implement this function:
[Html]
OnBackPressed ();
[2] How to click the Button (or other methods) in Android to implement the MENU function:
[Html]
OpenOptionsMenu ();
[3] android. view. WindowManager $ BadTokenException: Unable to add window -- token null is not for an application exception solution:
Reason: A Context variable, such as private Context mContext, is defined, and mContext = getApplicationContext () is used in onCreate (Bundle savedInstanceState. At the same time, add an AlertDialog prompt dialog box in the Activity and instantiate it as follows:
[Html]
AlertDialog. Builder builder = new AlertDialog. Builder (mContext );
In this case, an exception occurs! This error is reported in the new AlertDialog. builder (mcontext), although the parameter here is AlertDialog. builder (Context context), but we cannot use the Context obtained by getApplicationContext (). Instead, we must use Activity, because only one Activity can add a form.
Solution: use Activity. this (Activity is the name of your Activity) to fill the parameters in new AlertDialog. Builder (Context context) to create a correct Dialog.
[4] How to dynamically enable full screen and exit full screen in android:
[Html]
/**
* Dynamic full screen setting
*/
Private void setFullScreen (){
GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN, WindowManager. LayoutParams. FLAG_FULLSCREEN );
}
/**
* Cancel full screen dynamically
*/
Private void quitFullScreen (){
Final WindowManager. LayoutParams attrs = getWindow (). getAttributes ();
Attrs. flags & = (~ WindowManager. LayoutParams. FLAG_FULLSCREEN );
GetWindow (). setAttributes (attrs );
GetWindow (). clearFlags (WindowManager. LayoutParams. FLAG_LAYOUT_NO_LIMITS );
}
[5] How to obtain the SDCard directory path in Android:
[Html]
/**
* Get the directory path of SDCard
* @ Return
*/
Private String getSDCardPath (){
File sdcardDir = null;
// Determine whether an SDCard exists
Boolean sdcardExist = Environment. getExternalStorageState (). equals (android. OS. Environment. MEDIA_MOUNTED );
If (sdcardExist ){
SdcardDir = Environment. getExternalStorageDirectory ();
}
Return sdcardDir. toString ();
}
[6] To be continued...
From Android-Idea