mrehan
mrehan

Reputation: 1182

Activity shows up during phone call?

i have an activity it starts the service whenever user swipes to refresh.This service download some data from Internet and store it in shared preferences and put some Extras in intent to send to the activity.And In activity OnNewIntent() I am perfectly getting everything that I have put in that intent before.And on the base of these extras activity will get data from shared preferences and show it in listView. Every thing is fine i am not getting any kind of exceptions.

But the problem is:

when i swipe down to refresh (service will be started) and on that time I receive a phone call and my application's activity hides and phone call shows up so that i can pick up the phone call.Remember Service was already started before so when service completes its download task it starts the activity like i am pasting code:

//where i is intent and I have initialized it so no worries!  
i.setAction("xxxxx.CUSTOM_ACTION");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);

and that activity shows up during the phone call.I don't want it to show up,I want that activity to stay wherever it was even when service starts it by sending some intent. Please tell me if there is any intent flag that can solve my problem.Any help would be appreciated! if have any confusion about the problem do tell me I can explain more briefly.

Upvotes: 0

Views: 259

Answers (2)

Dhruba Bose
Dhruba Bose

Reputation: 446

You can continuously check running application list inside service, and push your activity.

You can save your HTTP response in shared preference or in Application instance. You can also use Broadcast Receiver for that purpose.

Using this you will get your foreground running application:

ActivityManager activityManager = (ActivityManager)
getSystemService(Context.ACTIVITY_SERVICE);
RunningTaskInfo foregroundTaskInfo = activityManager.getRunningTasks(1).get(0);
String foregroundTaskPackageName = foregroundTaskInfo .topActivity.getPackageName();

If your service lifetime exists within your application. Then you can use BindService.

Upvotes: 2

mesh
mesh

Reputation: 937

You can implement a Phone Call State listener which knows when the phone is idle, busy, or ringing. Add further logic to not to start your activity when the phone is busy. When it transitions from busy to idle only then start your activity.

This link has an example of Phone Call State Listener.

Upvotes: 1

Related Questions