How To Finish Activity In Broadcastreceiver OnCallEnded()
I have a question, how to finish activity in brodcastreceiver onCallEnded (SIP) . There is a brodcastreceiver like this: public class IncomingCallReceiver extends BroadcastReceiver
Solution 1:
First why can you add the listener in IncomingCallActivity itself. I dont think that will make any difference.
Second for your solution,
start your activity with a FLAG_ACTIVITY_SINGLE_TOP so that you receive the new Intent in onNewIntent(Intent intent) of the activity.
Then onCallEnded start the activity once again.
Intent i = new Intent(context, IncomingCallActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
i.putExtra("Close", true); // an extra which says to finish the activity.
context.startActivity(i);
Now in onNewIntent(Intent intent)
if(intent.getBooleanExtra("Close", false))
finish();
Solution 2:
You can do it like this:
@Override
public void onCallEnded(SipAudioCall call) {
// IncomingCallActivity.finish();
//Here set any value like an int
intToClose = 1;
}
then in your activity check for the intToClose
, if its 1 then just call fnish();
UPDATE: This code is from my mind, so it can have some errors. Add this to your current activity, or something like this:
scheduler = Executors.newSingleThreadScheduledExecutor ( );
scheduler.scheduleAtFixedRate ( new Runnable ( ) {
public void run ( )
{
runOnUiThread ( new Runnable ( ) {
public void run ( ) {
closeInt = IncomingCallReceiver.intToClose;
if ( closeInt == 1 ) {
scheduler.shutdown ( );
finish ( );
}
}
} );
}
}, 750, 750, TimeUnit.MILLISECONDS );
Solution 3:
I used this code my problem solved.
Try this your problem will be solve. there is no
endcall
in broadcast sofinish()
on Idle state. Happy coding!!if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { ((Activity)context).finish(); }
Post a Comment for "How To Finish Activity In Broadcastreceiver OnCallEnded()"