How to return back to Ongoing Call

Hi Team,
After connection established on audio / video call when i pressed back button the ongoing call screen closed…

How to resume with the ongoing call screen for both audio and video call

1 Like

Kindly reply to this

Hey @aupriya
You can use CometChat.getActiveCall() to get active call with that call object you can have necessary data to start your call again

1 Like

hi @mangesh.yadav,

I want to resume with the ongoing call.

when i use
Intent callIntent = new Intent(getActivity(), CallActivity.class);
callIntent.putExtra(StringContract.IntentStrings.SESSION_ID, CometChat.getActiveCall().getSessionId());
getActivity().startActivity(callIntent);

the screen was white and no other things can be able to rather than clicking the back button.

This is the callactivity

public class CallActivity extends AppCompatActivity implements CallActivityContract.CallActivityView {

private RelativeLayout callView;

private String sessionId;

private static final String TAG = "CallActivity";

private CallActivityContract.CallActivityPresenter callActivityPresenter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call);

    callActivityPresenter=new CallActivityPresenter();
    callActivityPresenter.attach(this);
    callView = findViewById(R.id.call_view);


    if (getIntent().hasExtra(StringContract.IntentStrings.SESSION_ID)) {
        sessionId = getIntent().getStringExtra(StringContract.IntentStrings.SESSION_ID);
        Logger.error(TAG, " sessionId " + sessionId);
        CometChat.startCall(CallActivity.this, sessionId, callView, new CometChat.OngoingCallListener() {
            @Override
            public void onUserJoined(User user) {
                Logger.error(TAG, " Name " + user.getName());
            }

            @Override
            public void onUserLeft(User user) {
                Log.d(TAG, "onUserLeft: "+user.getName());
            }

            @Override
            public void onError(CometChatException e) {

                Log.d(TAG, "onError: "+e.getMessage());
            }

            @Override
            public void onCallEnded(Call call) {
                Log.d(TAG, "onCallEnded: "+call.toString());
                finish();
            }
        });
    }
}

@Override
protected void onStart() {
    super.onStart();
    callActivityPresenter.addCallListener(this,TAG);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    callActivityPresenter.removeCallListener(TAG);
}

}

What i have to do to resume with the ongoing call

1 Like

Hey @aupriya

If you want return to activity from killed state then you have to store the sessionId and call the startCall method on launch of the call activity. You can call the startCall again in onResume() of the activity as shown below:

public class CallActivity extends AppCompatActivity implements CallActivityContract.CallActivityView {

    private RelativeLayout callView;
    private String sessionId;
    private static final String TAG = "CallActivity";
    private boolean isFirstLaunch;
    private CallActivityContract.CallActivityPresenter callActivityPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call);

        callActivityPresenter = new CallActivityPresenter();
        callActivityPresenter.attach(this);

        callView = findViewById(R.id.call_view);

        if (getIntent().hasExtra(StringContract.IntentStrings.SESSION_ID)) {
            sessionId = getIntent().getStringExtra(StringContract.IntentStrings.SESSION_ID);
        }

        startCall(sessionId);
    }

    private void startCall(String sessionId) {
        Logger.error(TAG, " sessionId " + sessionId);
        CometChat.startCall(CallActivity.this, sessionId, callView, new CometChat.OngoingCallListener() {
            @Override
            public void onUserJoined(User user) {
                Logger.error(TAG, " Name " + user.getName());
            }

            @Override
            public void onUserLeft(User user) {
                Log.d(TAG, "onUserLeft: "+user.getName());
            }

            @Override
            public void onError(CometChatException e) {
                Log.d(TAG, "onError: "+e.getMessage());
            }

            @Override
            public void onCallEnded(Call call) {
                Log.d(TAG, "onCallEnded: "+call.toString());
                finish();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        callActivityPresenter.addCallListener(this,TAG);
        if (isFirstLaunch&&sessionId!=null){
            startCall(sessionId);
        }else {
            isFirstLaunch = true;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        callActivityPresenter.removeCallListener(TAG);
    }
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.