954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Restoring App after phone call

Hi I have an app for Android phones.

It is working as intended but when I receive a phone call the app is minimised(but still running) and I have to open the app again.

I was wondering how do I make it so after the phone call it restores my app.

I've found other apps can do this e.g. angry birds but I'm struggling to find examples online.

ajst
Junior Poster
121 posts since Nov 2010
Reputation Points: 30
Solved Threads: 3
 

Use PhoneStateLisenter to listen out for changes in the call state, with the onCallStateChanged method.
Once state change from CALL_STATE_OFFHOOK to CALL_STATE_IDLE trigger/wake-up your application

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Thanks thats exactly how I ended up doing it.

I stored my phones state and compared it to the current phone state to notice a change.

then set set an alarm which triggers my app to open 10 secs later.

here is the code if anyone else gets stuck like I did.

youActivity act = this;
AlarmManager mgr = (AlarmManager)act.getSystemService(Context.ALARM_SERVICE);
RESTART_INTENT = PendingIntent.getActivity(this.getBaseContext(), 0, new Intent(getIntent()), getIntent().getFlags());
.
.
.
if(Globals.lastPhoneState != Globals.telephonyManager.getCallState())
        {
	        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 10000, RESTART_INTENT);
        }
ajst
Junior Poster
121 posts since Nov 2010
Reputation Points: 30
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: