Why is my main activity blackscreen/hidden when returning from another activity?
-
16-06-2021 - |
Question
My app uses the ES File Explorer for loading/saving files using the com.estrongs.action.PICK_FILE intent. It goes to the browser ok does its' stuff and returns the result but on returning to the main activity, the main not visible. It is focused. I can use the fling gesture and the keyboard opens when you press an edittext (hidden). The OnActivityResult() is called and also processed fine. I do not have any code in my onResume, OnStop etc. I have added the logcat below but as you can see it doesn't really show anything.
I don't know if it is worth mentioning but I also use the SherlockActionBar.
Finally this is the funny bit. My activity has a tabhost with basically 2 main views. 1 is a ListView and 1 is a custom view using OnDraw(). If I load a file which has to be displayed on the listview all is ok. If I load a file for the custom view it is hidden.
Please where is my fatal flaw?
the intent is started like this
intent = new Intent("com.estrongs.action.PICK_FILE");
intent.putExtra("com.estrongs.intent.extra.TITLE", "Open");
goingtobrowser = true;
startActivityForResult(intent, REQUEST_CODE_PICK_FILE_OR_DIRECTORY);
and the OnActivityResult() is like this
if (resultCode == RESULT_OK && data != null) {
// obtain the filename
if (D)
Log.e(TAG, "++ Coming back from Browser ++");
Uri fileUri = data.getData();
if (fileUri != null) {
String filePath = fileUri.getPath();
if (filePath != null) {
//do something with the path
}
}
}
06-21 11:16:15.421: E/BTUI(12000): ++ ON START ++
06-21 11:16:15.421: D/BTUI(12000): ++ ON RESUME ++
06-21 11:16:15.571: W/KeyCharacterMap(12000): No keyboard for id -1
06-21 11:16:15.571: W/KeyCharacterMap(12000): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-21 11:16:15.801: D/dalvikvm(12000): GC_EXTERNAL_ALLOC freed 435K, 41% free 4138K/6983K, external 3976K/4039K, paused 29ms
06-21 11:16:15.841: D/dalvikvm(12000): GC_EXTERNAL_ALLOC freed 33K, 42% free 4105K/6983K, external 4000K/4885K, paused 27ms
06-21 11:16:19.121: E/BTUI(12000): ++ Going to Browser ++
06-21 11:16:19.171: D/BTUI(12000): ++ ON onSaveInstanceState ++
06-21 11:16:19.171: D/BTUI(12000): ++ ON PAUSE ++
06-21 11:16:19.611: D/BTUI(12000): ++ ON STOP ++
06-21 11:16:35.801: D/BTUI(12000): onActivityResult -1
06-21 11:16:41.351: E/BTUI(12000): ++ Coming back from Browser ++
06-21 11:16:42.481: E/BTUI(12000): ++ ON START ++
06-21 11:16:42.481: D/BTUI(12000): ++ ON RESUME ++
06-21 11:17:07.751: I/System.out(12000): in onFling() ::
**EDIT After looking more on 1st load up the cusotom views' onDraw() is called so I put a customview.invalidate() in the main activities onResume(). So when returning from the 2nd activity this should be called and the view invalidates and calls onDraw(). It is not! I guess this is the problem. Please some ideas??
**EDIT the only way i could get rid of the black screen was to invalidate the entire main screen with
ViewGroup vg = (ViewGroup) findViewById (R.id.main);
vg.invalidate();
in onResume().
BUT this is not suitable enough for me because I need to call view .invalidate() or view.postinvalidate() from other threads and this DOES NOT call the customview.onDraw() and the screen stays blank with these calls. Anyone??
Solution
I thought I would answer my own question and maybe someone can explain it better than me. The problem seem to be related to views surface callback on returning from another activity. I only managed to fix it by using a setContentView(). mainViewGroup.invalidate() I mentioned above didn't work. I then noticed that the view.invalidate() was inadequate for me so I switched it to a surfaceview. This exposed the callback problem.
If I removed the surfaceholder's view callback in surfaceDestroyed() it worked ok, the main returned fine. BUT dynamically re-attaching the callback in the onResume() wasn't working. The surfaceview was not-reattaching. So I STILL have to do a setContentView() to reset things. This works but I would like to hear a "cleaner" solution. Thanks for looking.