我有一个TabActivity
的应用程序,每当我从引擎(NDK C代码)获得回调时,我都会显示一个对话框。当应用程序处于恢复状态时,我确保显示对话框。
收到引擎回调后,我启动NetworkDownDialog
活动,但这会导致对话框停留一秒钟然后消失。如果我使用Dialog
或AlertDialog
,也会发生同样的事情。最奇怪的是,失踪似乎是随机的(并不总是发生)。
这是一款S3设备。发生了什么事?
2013年5月23日编辑
网络向下对话代码
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();
}
};
}
在日志中,这就是我所看到的:
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-------
显示活动对话框
**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)
在这种情况下,ActivityDialog
在上述之后消失了。
为什么我的对话框消失了?我的C级本机代码中的内存损坏是否可能导致此问题?我在UI方面做错了吗?我完全陷入困境......
编辑于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删除了我的tabactivity。这会导致对话框删除吗?
答案 0 :(得分:5)
答案 1 :(得分:3)
您获得的错误是由于在您呼叫dialog.show()
时屏幕没有准备好显示任何内容。
另一个(可能的)解决方案是使用如下例所示的系统对话框:
AlertDialog dialog = new AlertDialog.Builder(context)
.setMessage(text)
.setPositiveButton(R.string.ok, null)
.setCancelable(true)
.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
答案 2 :(得分:2)
看到您的代码后,我建议您删除finish()
中的BroadcastReceiver
并运行您的程序(用于测试目的)。您看到的问题可能是由于Activity
几乎同时开始和结束而发生的。
答案 3 :(得分:1)
答案 4 :(得分:1)
当我看到(频道〜消费者关闭输入频道)之后出现错误时,我发现它表明应用程序正在关闭设计或其他地方引发的异常。我的预感是,您要么终止活动,要么在对话框显示的同时遇到异常,导致您的应用开始退出。我还会在您调用完成的任何地方添加更多日志记录,以验证您在显示对话框时不会意外完成。
答案 5 :(得分:0)
很好的问题是c代码一些文件描述符fd腐败导致了这个问题。在c级解决问题没有看到问题。虽然很奇怪。