I have written this simple app to make a call based on handler delay by ms. However for some reason it crashes the app when I action the public void callme(View view) via button onClick event.
I am sure it is something simple, perhaps someone could point out my errors. Thanks
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.EditText;
public class CallButtonActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void callme(View view) {
EditText edit_seconds = (EditText)findViewById(R.id.seconds);
CharSequence edit_seconds_value = edit_seconds.getText();
int mSeconds = Integer.parseInt(edit_seconds_value.toString());
Handler myHandler = new Handler();
myHandler.postDelayed(mMyRunnable, mSeconds);
}
private Runnable mMyRunnable = new Runnable()
{
public void run()
{
EditText msisdn = (EditText)findViewById(R.id.msisdn);
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + msisdn));
startActivity(callIntent);
}
};
}
In this line…
It should be
time.getText().toString(). You also need to usegetText().toString()for the telephone number – NOT justgetText()as that (on anEditText) returns anEditableand not aString.I’m not sure, however, if using
findViewById(...)with aRunnableis legal although I may be wrong.