The title explains all... I have this snippet of code in my application:
String url = createTelUrl("3112007315");
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(url));
context.startActivity(intent);
It does make a call, but once the call ends, my application crashes. I'd like to return to my application once the call has finished, but I read this post and it seems not to be possible. So... is there anyway to at least pause my application and resume it once the call has finished?
EDIT:
Thanks for the two answers I received, I feel I'm really close to my goal... I had already done some of the things you guys suggested. But, maybe I didn't explain some details of the application... I'm developing Who Wants To Be A Millonarie game, so I need to implement calls (I don't know how it's called in USA or other countrys, but here we call it "call to a friend").
Anyway... I've done too many changes to this app and now it's not crashing. But, the Canvas where I draw the UI is not been showed once the called has ended.
I have a SurfaceView
that holds the UI. For that SurfaceView
I created a thread that is meant to refresh the UI... this is basically what the thread does:
@Override
public void run() {
Canvas c;
while (_run) {
c = null;
try {
c = _surfaceHolder.lockCanvas(null);
// Check if should wait
synchronized (_surfaceHolder) {
_panel.onDraw(c);
}
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
_surfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
But, once the call has ended I get a black screen. The surface is there (I know it because it still can receive some touch events), but it's not showing anything. Another thing to take in account is how I'm starting the Thread from the SurfaceView
class:
public void surfaceCreated(SurfaceHolder holder) {
hilo.setRunning(true);
try{
hilo.start();
}catch(IllegalThreadStateException ite){
Log.e("wwtbam", "god dammed");
}
}
This worked nice before I start implementing phone-calls. The problem here is that once the call has ended and it executes again the start method which throws a IllegalThreadStateException
because the thread has already been started. I've tried using some 'technics' to pause the UI thread while calling but I haven't been able to solve this problem. I tried doing something like:
// this in the UI thread class
if(haveToWait)
wait();
....
// this in the surface view class
if(callEnded)
hilo.notify();
But that didn't work. I also have tried some other 'tricks' like using sleep(50);
instead of wait();
but it does not work either.
With all that information I provided... what could you suggest to me?