How to call startActivity(new Intent
Why does this code crash my app onte emulator and on the device - at least in debug mode?
public void callResul开发者_C百科t(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
Have you added any thread ?? there can be problem if u have added thread. What error message comes in log-cat ?
精彩评论