0

I finished the code for my app months ago and everything worked great.

In the previous weeks I've updated some libraries and done some tweaks here and there but I haven't touch the specific class where the problem appeared.

When the user presses a button, he should be able to chose a file.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 1);

Then on that same class I have this

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null) {
        if (requestCode == 1) {
            if (resultCode == Activity.RESULT_OK) {
                selectedFile = data.getData();

But the window to chose a file never shows up, I just see a quick flash and nothing happens, so data is always null

This is the error I see on Logcat:

04-29 12:45:28.072 26104-26104/com.android.documentsui D/AndroidRuntime: Shutting down VM 04-29 12:45:28.072 26104-26104/com.android.documentsui E/AndroidRuntime: FATAL EXCEPTION: main Process: com.android.documentsui, PID: 26104 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.documentsui/com.android.documentsui.DocumentsActivity}: java.lang.RuntimeException: A TaskDescription's primary color should be opaque at android.app.ActivityThread.performLaunchActivity(ActivityThread.java) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java) at android.app.ActivityThread.access$800(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java) at android.os.Handler.dispatchMessage(Handler.java) at android.os.Looper.loop(Looper.java) at android.app.ActivityThread.main(ActivityThread.java) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) Caused by: java.lang.RuntimeException: A TaskDescription's primary color should be opaque at android.app.ActivityManager$TaskDescription.(ActivityManager.java) at android.app.Activity.onApplyThemeResource(Activity.java) at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java) at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)  at android.app.ActivityThread.access$800(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java)  at android.os.Handler.dispatchMessage(Handler.java)  at android.os.Looper.loop(Looper.java)  at android.app.ActivityThread.main(ActivityThread.java)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) 

I've looked on colors.xml and style.xml and there isn't any color with 8 characters to give transparency. The size of all colors is 6 hex characters.

I really don't understand what changed for this to sudenly stop working.

Yluna
  • 103
  • 2
  • 15
  • Turns out it was a device problem. I was testing it on a Xiaomi and aparently if MIUI optimization is disabled this happens. The more you know... – Yluna Apr 29 '19 at 15:01
  • I faced the same problem check this link https://stackoverflow.com/a/29166908/9612786 – ahmed mohammed Mar 02 '20 at 22:36

1 Answers1

0

Looks like one of the main colors (colorPrimary, colorPrimaryDark, colorAccent) of the activity you're trying to use for file selection (com.android.documentsui.DocumentsActivity) is transparent, which causes crash on lower android versions, the crash reason is not inside your code.

Also, if somebody is having the same crash when trying to start activity written by you - you need to check whether your app's primary colors are opaque. If they're transparent (using alpha parameter, for example #CC00BFFF - here CC is alpha parameter), if so - remove alpha parameter from your color.