Android: Activity Dialog / Dialog disappears unexpectedly
Asked Answered
M

6

6

I have an application with TabActivity in which I am displaying a dialog each time I get a callback from my engine (NDK C code). I make sure dialog is displayed when app is in resume state.

Upon receiving the callback from the engine, I start the NetworkDownDialog activity, but this causes the dialog to stay for a second and then disappear. The same thing happens if I use Dialog or AlertDialog. Most strangely, the disappearance seems random (doesn't always happen).

This is an S3 device. What's going on?

Edit on 23/05/2013

Network Down Dialog Code

public class NetworkDownDialog extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.network_down);
        Logger.d("NetworkDownDialog", "----------onCreate-----------");
        registerReceiver(mNetworkDownReceiver, new IntentFilter("NetworkDown"));
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mNetworkDownReceiver);
        Logger.d("NetworkDownDialog", "------onDestroy-------");
    }
    @Override
    protected void onResume() {
        super.onResume();
        Logger.d("NetworkDownDialog", "------onResume-------");
    }
    @Override
    protected void onRestart() {
        super.onRestart();
        Logger.d("NetworkDownDialog", "------onRestart-------");
    }
    @Override
    protected void onStart() {
        super.onStart();
        Logger.d("NetworkDownDialog", "------onStart-------");
    }
    @Override
    protected void onStop() {
        super.onStop();
        Logger.d("NetworkDownDialog", "------onStop-------");
    }
    @Override
    public void onBackPressed() {
        Logger.d("NetworkDownDialog", "------onBackPressed Do nothing-------");
    }
    private BroadcastReceiver mNetworkDownReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };
}

In the logs, this is what I see:

05-15 20:48:02.981 D/NetworkDownDialog( 1050): ------onCreate-------
05-15 20:48:02.981 D/alsa_ucm(  202): Setting mixer control: RX5 MIX1 INP2, value: RX2
05-15 20:48:02.991 D/alsa_ucm(  202): Setting mixer control: RX6 DSM MUX, value: DSM_INV
05-15 20:48:02.991 D/alsa_ucm(  202): Setting mixer control: LINEOUT2 Volume, value: 100
05-15 20:48:02.991 D/alsa_ucm(  202): Setting mixer control: LINEOUT4 Volume, value: 100
05-15 20:48:02.991 D/NetworkDownDialog( 1050): ------onStart-------
05-15 20:48:02.991 D/alsa_ucm(  202): Setting mixer control: RX5 Digital Volume, value: 65
05-15 20:48:02.991 D/NetworkDownDialog( 1050): ------onResume-------

Activity Dialog displayed

 **05-15 20:48:05.073 W/InputDispatcher(  716): channel ~ Consumer closed input channel or an error occurred.  events=0x9
05-15 20:48:05.073 E/InputDispatcher(  716): channel ~ Channel is unrecoverably broken and will be disposed!**
05-15 20:48:05.073 W/InputDispatcher(  716): Attempted to unregister already unregistered input channel
05-15 20:48:05.083 I/SurfaceFlinger(  195): id=2033 Removed idx=5 MapSz=4
05-15 20:48:05.083 D/KeyguardViewMediator(  716): setHidden false
05-15 20:48:05.103 I/Adreno200-EGLSUB(  195): <CreateImage:897>: Android Image
05-15 20:48:05.103 I/Adreno200-EGLSUB(  195): <GetImageAttributes:1106>: RGBA_8888
**05-15 20:48:05.103 E/BufferQueue(  195): [mypackage.NetworkDownDialog] dequeueBuffer: SurfaceTexture has been abandoned!
05-15 20:48:05.103 E/SurfaceTextureClient( 1050): dequeueBuffer failed (No such device**)
05-15 20:48:05.103 D/PhoneStatusBar(  894): addNotification score=0
05-15 20:48:05.123 E/ViewRootImpl( 1050): Could not lock surface
05-15 20:48:05.123 E/ViewRootImpl( 1050): java.lang.IllegalArgumentException
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.Surface.lockCanvasNative(Native Method)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.Surface.lockCanvas(Surface.java:88)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2314)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.ViewRootImpl.draw(ViewRootImpl.java:2277)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2145)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1956)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.Choreographer.doFrame(Choreographer.java:525)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.os.Handler.handleCallback(Handler.java:615)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.os.Handler.dispatchMessage(Handler.java:92)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.os.Looper.loop(Looper.java:137)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at android.app.ActivityThread.main(ActivityThread.java:4918)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at java.lang.reflect.Method.invokeNative(Native Method)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at java.lang.reflect.Method.invoke(Method.java:511)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
05-15 20:48:05.123 E/ViewRootImpl( 1050):   at dalvik.system.NativeStart.main(Native Method)

In this case, the ActivityDialog disappeared after the above.

Why is my dialog disappearing? Is it possible that memory corruption at my C level native code is causing this problem? Am I doing something wrong on the UI side? I'm totally stuck...

Edit on 24 -05 -2013

05-24 19:49:00.025 I/SurfaceFlinger( 1901): id=2147 Removed NainTabActivity idx=3 MapSz=4

05-24 19:49:00.025 I/SurfaceFlinger( 1901): id=2147 Removed NainTabActivity idx=-2 MapSz=4

SurfaceFlinger removed my tabactivity.Will this can cause dialog remove?

Megasporangium answered 15/5, 2013 at 11:40 Comment(8)
are u sure, u are not calling cancel dialog in this process ?Idleman
No i am not calling Cancel.Megasporangium
What are the hardware acceleration options set?Enact
@ shoe rat android:hardwareAccelerated is not set! is it required?Megasporangium
In case you need native access to window surfaces, I believe you will need a ACCESS_SURFACE_FLINGER permission. Either that, or you're not passing a Surface .... But I think it might be due to the context going stale. Destroy the window in onStop() and recreate it in onCreate() and see if that changes something.Threap
Capture the whole SurfaceFlinger and WindowManager logs, the 'eror log' you posted is too short and is lacking the real reason why the window has leaked/lost from the screen.Threap
@Megasporangium is this issue resolved ? whats is the mystry behind this issue ?Idleman
@421 Well well problem was with c code some file descriptor fd corrupt was causing this issue..pretty strange though..Megasporangium
M
0

Well well problem was with c code some file descriptor fd corrupt was causing this issue.once the issue was solved at c level the problem is not seen.pretty strange though.

Megasporangium answered 10/9, 2014 at 6:13 Comment(0)
I
5
  1. Make Sure that the you are displaying the dialog with application context.
  2. Make sure no two events come and hit the same part of code.i.e when you are about to display the dialog,one more event from c code to display the dialog.
  3. Make Sure your application has enough memory to run smoothly.
Idleman answered 15/5, 2013 at 11:58 Comment(4)
1)Activity is started with TabActivity Context.2) is taken care.3)Right,but is the toughest part to know.Megasporangium
Does not look like an out of memory issue, from ViewRootImpl.java : Log.e(TAG, "Could not lock surface", e); Don't assume this is due to out of memory, it could be something else, and if it is something else then we could kill stuff (or ourself) for no reason.Enact
@Megasporangium did you use custom dialog?can you please post your dialog code?Pileup
@Pratik please find my Activity Dialog code.Custom dialog code was done using extending Dialog class.Megasporangium
C
3

The error you are getting is due to not having the screen ready to display anything at the time you are calling the dialog.show().

Another (possible) solution for you is to use a system dialog like in this example:

AlertDialog dialog = new AlertDialog.Builder(context)
    .setMessage(text)
    .setPositiveButton(R.string.ok, null)
    .setCancelable(true)
    .create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Cartridge answered 22/5, 2013 at 14:9 Comment(1)
We make sure the activity is in resume before we show dialog.Megasporangium
C
2

After seeing your code, I would recommend that you remove finish() in your BroadcastReceiver and run your program (for testing purposes). The problem you're seeing may happen due to having your Activity starting and ending almost at the same time.

Cartridge answered 24/5, 2013 at 5:1 Comment(1)
Finish call is taken care well!Megasporangium
S
1

I think the problem is due to the surface not being locked. Here are some solution which I found at SO.

Hope they help.

android-canvas-locking and android-draw-on-camera-preview

Subir answered 23/5, 2013 at 5:41 Comment(0)
J
1

When I have seen(channel ~ Consumer closed input channel) before followed by an error I have found it to indicate that the app was closing either by design or an exception raised elsewhere. My hunch would be that you are either terminating your activity or encountering an exception around the same time the dialog is displaying causing your app to start to exit. I'd also add more Logging to any place you call finish to verify you aren't accidentally finishing as you display the dialog.

Jallier answered 24/5, 2013 at 0:35 Comment(1)
Finish call is taken care well!Megasporangium
M
0

Well well problem was with c code some file descriptor fd corrupt was causing this issue.once the issue was solved at c level the problem is not seen.pretty strange though.

Megasporangium answered 10/9, 2014 at 6:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.