启动活动不适用于 Android 模拟器
我使用我的自定义实现 tabhost。创建一个新活动,如下所示:
public class TabsActivityGroup extends ActivityGroup {
//
//...
//
private void startGroupActivity(String activityID, Intent activityIntent) {
final LocalActivityManager localActivityManager = getLocalActivityManager();
Window window = localActivityManager.startActivity(activityID, activityIntent);
// after call destroy activity window equals null on android 1.6 (emulator). Why?
// on android 2.2 window not equal null
if (window != null) {
View view = window.getDecorView();
tabsContentFrameLayout.addView(view, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
}
}
//
//...
//
}
但在调用后销毁活动:
getLocalActivityManager().destroyActivity(className, true);
我正在尝试调用以启动活动,但从此代码中获取窗口等于 null:
Window window = localActivityManager.startActivity(activityID, activityIntent);
在具有固件 2.1 (Hero) 和 2.2 (Desire) 的设备上工作一切正常,但是在android平台的模拟器上不起作用;(
现在我正在研究android平台2.2的源代码,以理解为什么window等于null。
我会很高兴得到任何帮助。
临时解决方案:
public static boolean isEmulator(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String deviceId = telephonyManager.getDeviceId();
if (deviceId == null) return true;
if (CommonHelper.isNotNull(deviceId) && deviceId.equals(NULL_IMEI)) {return true;} else { return false;}
}
if (!isEmulator(this)) {
getLocalActivityManager().destroyActivity(className, true);
}
I use my custom implementation tabhost. Create a new activity as follows:
public class TabsActivityGroup extends ActivityGroup {
//
//...
//
private void startGroupActivity(String activityID, Intent activityIntent) {
final LocalActivityManager localActivityManager = getLocalActivityManager();
Window window = localActivityManager.startActivity(activityID, activityIntent);
// after call destroy activity window equals null on android 1.6 (emulator). Why?
// on android 2.2 window not equal null
if (window != null) {
View view = window.getDecorView();
tabsContentFrameLayout.addView(view, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
}
}
//
//...
//
}
But after call destroy activity:
getLocalActivityManager().destroyActivity(className, true);
I'm trying to make call to start activity, but get window equal null from this code:
Window window = localActivityManager.startActivity(activityID, activityIntent);
On a device with firmware 2.1 (Hero) and 2.2 (Desire) works all good, but on emulator with android platform not work ;(
Now I am studying source code android platform 2.2, to understand why window equal null.
I will be glad of any help.
Temporary solution:
public static boolean isEmulator(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String deviceId = telephonyManager.getDeviceId();
if (deviceId == null) return true;
if (CommonHelper.isNotNull(deviceId) && deviceId.equals(NULL_IMEI)) {return true;} else { return false;}
}
if (!isEmulator(this)) {
getLocalActivityManager().destroyActivity(className, true);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该调用是否适合启动活动?
我看到 startActivity 仅采用 Intent 的一个参数..
请查看。另外,嵌入 try/catch 中以获取异常(如果有)。
Is the call right for start activity?
I see that startActivity takes only one parameter of Intent..
Kindly check. Also, embed within try/catch to get the exception if any..