如何调用startActivity(new Intent
为什么此代码会使我的应用程序在模拟器和设备上崩溃 - 至少在调试模式下?
public void callResult(SRButton srb){
SearchResultsElement e = srb.getItem();
if (e.getTelephone() != null && e.getTelephone().length()>=7){
final String telno = e.getTelephone();
if(mHandler==null)
mHandler = new Handler();
mHandler.post(new Runnable(){
public void run(){
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+telno)));
}
});
}
}
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+telno)));
行与某些按钮 onclick 事件处理程序中使用的行相同,并且在那里工作正常,但是当我将该行放在活动的 onOptionsItemSelected 方法中的 callResult 调用中,它会导致 A) 拨号器正确显示,但 B) 我的应用程序在主活动中重新启动。 假设我的应用程序正常启动,进入主菜单屏幕,然后单击一个按钮,使屏幕(活动)2 出现在顶部,然后单击一个按钮,使屏幕 3 出现在顶部,然后当该屏幕上的按钮具有焦点我使用菜单并单击一个调用我的 callResult 方法的选项,拨号器显示正确,但是当我从那里点击后退按钮时,我返回到我的应用程序主菜单屏幕。我的另外两个屏幕消失了,我怀疑我的主菜单活动已重新启动,即 onCreate 被调用。
谢谢
Why does this code crash my app onte emulator and on the device - at least in debug mode?
public void callResult(SRButton srb){
SearchResultsElement e = srb.getItem();
if (e.getTelephone() != null && e.getTelephone().length()>=7){
final String telno = e.getTelephone();
if(mHandler==null)
mHandler = new Handler();
mHandler.post(new Runnable(){
public void run(){
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+telno)));
}
});
}
}
The line startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+telno)));
is the same line used in some button onclick event handlers and works fine there, but when I put the line in the callResult call in the onOptionsItemSelected method of an activity it causes A) the dialer to appear properly but then B) my app to restart at the main activity.
So lets say my app starts normally and I get to my Main Menu screen, then I click a button that causes screen(Activity) 2 to appear on top, then I click a button which causes screen 3 to appear on top and then when a button on that screen has focus I use the menu and click an option there which call my callResult method the dialer appears correctly but then when I hit the back button from there what I return to is my apps Main Menu screen. My other two screens are gone and I suspect my Main Menu activity has been restarted, ie onCreate recalled.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你添加了任何线程吗?如果您添加了线程,可能会出现问题。 log-cat 中出现什么错误消息?
Have you added any thread ?? there can be problem if u have added thread. What error message comes in log-cat ?