Android: couldn't save which view has focus because the focused view ### has no id

本文介绍了两种解决Android应用中视图焦点丢失问题的方法。一种是在配置文件中设置Activity属性,另一种是确保SurfaceView的线程正确创建和销毁,避免生命周期冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

Android: couldn't save which view has focus because the focused view ### has no id



可能引起原因有两种,对应解决方法如下:

解决方案一:

<application

android:icon="@drawable/icon" android:label="@string/app_name" >

<activity

android:label="@string/app_name"

android:configChanges="orientation|keyboardHidden|keyboard|screenLayout"

android:name=".Main" >

<intent-filter >

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>


解决方案二:

What probably happened is that you created a thread in the surfaceCreated() method but didn’t stop it or get rid of it in the surfaceDestroy() method.

When you didn’t give a theme for the preferences, it took over the whole screen and your old surface was destroyed. But when you specified a dialog-like theme, the old surface was still there because it was visible underneath the preferences.

public void surfaceCreated(SurfaceHolder holder)
{
if (_thread == null ||_thread.getState() == Thread.State.TERMINATED)
{
_thread = new TutorialThread(getHolder(), this);
_thread.setRunning(true);
_thread.start();
}
else
{
_thread.setRunning(true);
_thread.start();
}
}

This solved the problem for me, a thread’s start method cannot be called twice, so I had to reallocate…

http://forums.pragprog.com/forums/138/topics/4085


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值