1.I want to make the Phone Call From App Fragment page Button clicked its works Fine.
2.after Making Call From Fragment Page.Its Restarting the APP.
3.I want to Stop this.Just need to Open same Fragment Page,without Restarting the Application
MY Code:
private class MyPhoneListener extends PhoneStateListener
{
private boolean onCall = false;
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
switch (state)
{
case TelephonyManager.CALL_STATE_RINGING:
// phone ringing...
//Toast.makeText(FindStores_tabviewonclick_showpage.this, incomingNumber + " calls you", Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// one call exists that is dialing, active, or on hold
//Toast.makeText(FindStores_tabviewonclick_showpage.this, "on call...", Toast.LENGTH_SHORT).show();
//because user answers the incoming call
onCall = true;
break;
case TelephonyManager.CALL_STATE_IDLE:
// in initialization of the class and at the end of phone call
// detect flag from CALL_STATE_OFFHOOK
if (onCall == true)
{
//Toast.makeText(Find_stores.this, "restart app after call", Toast.LENGTH_LONG).show();
Log.i("AFTER PHONE Call", "restart app");
// restart our application
Intent restart = getActivity().getPackageManager().getLaunchIntentForPackage(getActivity().getPackageName());
restart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//.restart.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(restart);
onCall = false;
}
break;
default:
break;
}
}
}
Change the flag for intent in TelephonyManager.CALL_STATE_IDLE:
Intent restart = getActivity().getPackageManager().getLaunchIntentForPackage(getActivity().getPackageName());
restart.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(restart);