此问题与如何通过命令行关闭Android模拟器相同.
但是,尝试从第一个答案建议的解决方案后adb emu kill,我没有证明成功.
我正在为Android应用程序自动化单元测试.我的bash脚本在无头机器上运行.它创建一个使用该属性android create avd并emulator使用该-no-window属性执行的Android设备.然后它编译测试项目,使用连接到模拟器adb,安装项目并执行我的测试.一切正常.
现在我需要终止模拟器进程,就像引用的帖子一样,我只能使用它kill -9.
从命令行管理AVD的Google教程仅提到了如何在GUI环境中停止模拟器.
任何帮助表示赞赏.
我试图将多个textviews添加到已经膨胀的布局中。显示的信息是从数据库中提取的,为数据库中的每一行都创建了一个textview。由于数据库可能非常大,因此我在后台线程中一次创建一个textview,然后将其添加到前台。
这是在后台线程中调用的用于更新前台的函数:
private TextView temp;
private void addClickableEvent(ReviewHistoryEvent e){
if(e == null){
Log.e(tag,"Attempted to add a null event to review history");
return;
}
TextView t = new TextView(getBaseContext());
t.setTag(e);
t.setText(e.getTime()+" "+e.getEvent());
t.setClickable(true);
t.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
t.setTextAppearance(getBaseContext(), R.style.Information_RegularText);
t.setGravity(Gravity.CENTER);
t.setOnClickListener(this);
temp = t;
runOnUiThread(new Runnable() {
public void run() {
LinearLayout display = (LinearLayout) findViewById(R.id.reviewHistory_display);
display.addView(temp);
}
});
}
Run Code Online (Sandbox Code Playgroud)
此函数成功运行一次,并出现第一个textview。但是,当第二次调用它时,它在display.addView(temp);上失败。符合以下错误:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the childs's parent first.
Run Code Online (Sandbox Code Playgroud)
我不确定为什么我的textview如果已经被新实例化,为什么已经有一个父级。另外,我使用临时文本视图来绕过我的可运行对象,而无法引用本地文本视图t。它是否正确?任何帮助,将不胜感激。