Daily development encountered a variety of development problems, picked up a part to share. Some of the problems are very simple and fall into the coding specification category, while others are specific and less common. Not quite accurate place, welcome to discuss together ~

1.requestFeature() must be called before adding content

requestWindowFeature(Window.FEATURE_NO_TITLE); // Hide the titleCopy the code

Call onCreate before onCreate; otherwise an error will occur on models 4.4.2:

Calling startActivity() from outside of an Activity context requires the FLAG_NEW_TASK flag.

public static void openBrowser(Context context, String url) {
    Uri uri = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
Copy the code

FLAG_ACTICITY_NEW_TASK (ok on other phones)

3. The color value of TextView is invalid

titleTv.setTextColor(colorId); Titletv. setTextColor(ContextCompat. GetColor (context,colorId)); titletv. setTextColor(ContextCompat. // The right wayCopy the code

4. Internationalization reference problem a. Static/class global variables need to be judged separately; B. String with double quotation marks

<string name="Chinese"</string> <string name="Chinese">"In the article"</string>
Copy the code

Note: Using application.getString does not switch the resource content referenced in this way after switching the language. You can use the getString method in another activity instead

Free access to more information on Android development architecture (including Fultter, Advanced UI, performance optimization, architect course, NDK, Kotlin, Hybrid development (ReactNative+Weex) and interview topics on Android from leading Internet companies can be added[Tencent @ Android Advanced advanced]

5. Meizu 7.0 system flashes back after clicking in webView

ActivityManagerForce Removing ActivityRecord{6DD5804 u0 package name/current WebviewActivity T8819}: App died, no saved StateCopy the code

The onCustumView method is not supported

6. The default English on button is uppercase

android:textAllCaps="false"
Copy the code

7. Vivo cannot open the specified page after receiving push (there is no response at all)

The system will automatically pop up, but enter the Settings to open.

TextView uses WrapContent, lines=1 but the content is not fully displayed only in the part of the screen, in the part of the screen, not when the property animation is pulled out. (This problem occurs when customizing horselight controls)

public static int getTextViewLength(TextView view, String text) {
    TextPaint paint = view.getPaint();
    int textLength = (int) Layout.getDesiredWidth(text, 0, text.length(), paint);
    return textLength;
}
Copy the code

And then I set the width of the TextView.

9. No Activity found to handle the Intent {act = android. Intent. Action. VIEW_DOWNLOADS FLG = 0 x10000000} samsung SM – C7000 (C7) The 6.0.1 system will have this problem

if(intent.resolve(context.getPackageManager))! =null){ ... }Copy the code

When using an implicit intent for startActivity, it’s best to include this judgment and try catch, because you can’t be sure which type will fail

10. Set dialog corners

getWindow().setBackgroundDrawableResource(R.drawable.widget_dialog_round_corner);
Copy the code

E/rsC++(16241): RS CPP error: Blur radius out of 0-25 pixel bound

TextView shadowRadius cannot be greater than 25. This is a problem in XML code.

This is also the cause of partial ambiguity, including under the button.

If the content contains the words “hongbao”, the picture will be invalid and cannot be displayed (the subject of sharing can be seen by himself).

13. If the App on Xiaomi mobile phone is opened with apK at the end of the browser, it cannot be downloaded and installed normally. The address of Ali Cloud and App Treasure will be intercepted to download and install by using xiaomi mobile phone system’s own downloader, which will use thunderbolt download component by default. After the address of Aliyun is downloaded, click push to complete the download, and the file will be displayed as unrecognizable (while the address of App Bao can be installed normally). The download address of Miui and Huawei applications and the address ending with non-. APk will jump into the browser for download according to the normal process. After closing the function of Xunlei download component on Xiaomi mobile phone, it can be installed normally by clicking Push, and there will be no problem that files cannot be identified. So the solution to this problem is very simple, change the download address to a non-APK ending address.

14. The desktop icon is not replaced

android:roundIcon="@mipmap/logo"
Copy the code

This property is also set in application

The reason for the blank screen is that it takes time for the system to start up (the background is white by default). General practice:

Set the Theme

<style name="MNoActionBar" parent="Theme.AppCompat.NoActionBar"> <! --<item name="android:windowFullscreen">false</item>--> <! --<item name="android:windowBackground">@drawable/welcome</item>// this line can set the background image for the window. If this line is set separately, there is no delay in opening it without transparency"android:windowIsTranslucent">true</item> </style> </style> </style>Copy the code

Specific to an activity: If an activity displays both a full-screen startup image and the latest content (not full-screen) after the content has loaded, then the relevant methods should be set:

private void setFullScreenEnable(boolean isEnable) {
    if(isEnable) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Hide status bar}else{ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Display status bar}}Copy the code

If you are on a page with a Webview, you can set this in the onCreate method and the onpageFinished callback, respectively.

Special case: If the entire page is loaded with H5, even if the above Settings are used, the screen will still flash by. This is caused by the rendering of the H5 page itself, so the current treatment method is to make a delay effect for the start page, so as to cover the moment when the white screen flashes by: FullLoadingView. PostDelayed (new Runnable () {/ / needs to be done under delay, otherwise there will be a page for an instant of white (should be page rendering H5)

    @Override    public void run() {        fullLoadingView.setVisibility(View.GONE);        setFullScreenEnable(false);    }}, 300);
Copy the code

If application B opens application A’s cActivity, other activities of application A will also be opened. This is due to taskAffinity, which shares the same task stack. So set up another task stack in the manifest file:

android:taskAffinity=".payAct"
Copy the code

17. Get the bitmap of the WebView to set the height of the webview according to the height of the page. At the same time, H5 good fit, equal ratio of width and height. At the same time, it is possible to retrieve bitmap information with blank UI content, which is delayed because the onPageFinished method just pulls the code, not the page is rendered.

webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
Copy the code

When set to NARROW_COLUMNS, shared images cannot be spread full-screen if the Webview itself is not full-screen.

Error inflating class ImageView Xml: Inflating class ImageView Xml: Inflating class ImageView Xml

Insert a picture description here

This is because the image resource file is placed in a lower version folder, so the higher version is not inflate.

19. The EditText who attributes

android:digits="0123456789"
Copy the code

Often used to restrict the input format of EditText.

20. The android Studio global search results are not fully cached

Insert a picture description here

21. BottomSheetDialog sets rounded corners

<style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item>
</style>
<style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background"> @ android: color/transparent < item > < / style > new BottomSheetDialog (context, R.s tyle. BottomSheetDialog) / / set styleCopy the code

22. Invalid LinearLayout layout_weigt in ScrollView

android:fillViewport="true" 
Copy the code

23.Process ‘command ‘E:\android\tool\ SDK \build-tools\26.0.3\aapt.exe’ finished with non-zero exit Value Build and upgrade versions are invalid because the code is not standard!

android:drawableTop="2dp"// Error code!!Copy the code

In general, the problem can be compared to the next file history to see what resources file reference and other non-standard places, really can not find back to the version to see.

24. The TextView displayed in dialog is incomplete because contenttv.settext (html.fromhtml (content)) is used; Instead of directly contenttv.settext (content); The former doesn’t work either, or the text may contain the wrong HTML tag text, so you need to consider compatibility when using it.

25. Floating point accuracy problem

demo

Therefore, it is better to use BigDecimal for business purposes.