Return to ongoing call in Android

Problem Statement
How to i return to ongoing call when my app is in background or I am on some other activity. I am aware of Cometchat.startCall() method but that does not work. Also am I suppose to create my own notification for that purpose or their is some easy way out. Please elaborate in detail.

What I Did

I created notification when the call is picked up.The Notification has a button called Return to call which when pressed sends a broadcast. In My receiver I have called CometChat.startCall() method by passing all the required parameters. But for some reason it does not start that activity.


Hello @PranavKapadne,
Can you please let me know if you get any errors in the onError callback or in the logs when the startCall() method is called.
Also, please share the code snippet with me where you call the startCall method so that i can have a look at it.


This is Broadcast Receiver

public class CometChatCallReceiver extends BroadcastReceiver {

public CometChatCallReceiver(){

Activity activity;
public CometChatCallReceiver(Activity activity){
    this.activity = activity;

public void onReceive(Context context, Intent intent) {

    String sessionId = intent.getStringExtra("session_id");
    CometChat.startCall(activity, sessionId, CometChatCallActivity.mainView, new CometChat.OngoingCallListener() {
        public void onUserJoined(User user) {


        public void onUserLeft(User user) {


        public void onError(CometChatException e) {


        public void onCallEnded(Call call) {




onError return me Null

Hello @PranavKapadne
The session id you need to pass to startCall() method is the session ID of the active call. This can be obtained as below:
String activeCallSessionId = null ;
if(CometChat.getActiveCall != null)
activeCallSessionId = CometChat.getActiveCall().getSessionId();
Log.d(“CometChat” , “No Active Call”);

Now instead of sessionId, pass the activeCallSessionId to the startCall() method

Hope this helps

No it didn’t work. App crashes in onError() callback of startCall() with NullPointerException.

Can you please share the code where you are starting the CometChatCallActivity ??

I have just added CometChatCallListener.addCallListener(“MyDriefcaseMenu”,this,broadcastIntent); to onResume of my activity.

But the CometChatCallActivity needs to be started from the receiver as the view is in that activity. The activity should be started with the session id…the view to launch the call is in that activity

So do you mean that i should not call CometChat.startCall() method in the receiver?. It should be replace by startActivity(new Intent(this,CometChatCallActivity)).

I don’t know how you have implemented this at your end. However, to join the ongoing call, you need a RelativeLayout to be passed to the startCall method. And as there is no view associated with a Receiver, you cannot start the call from a receiver.
The basic idea to join an already ongoing call is, to obtain the sessionID of the ongoing call using the getActiveCall() method. and then call the startCall() method with the same session id

hope this helps

See the problem is there is no way i can return to the ongoing call if i am out of the CometChatCallActivity. So to overcome this i created a notification when i receive a call in onIncomingCallReceived() of the CometChatCallListener.addCallListener(). This notification has button which when clicked sends a broadcast to my receiver. The onReceive of the receiver has following code to start call.
Below is my small snippet

    CometChat.startCall(CometChatCallActivity.callActivity, activeCallSessionId, CometChatCallActivity.mainView, new CometChat.OngoingCallListener() 


If the Above approach is incorrect please help me out with that.

Hello @PranavKapadne
As mentioned above, to join the ongoing call you need to pass a view to the startCall method. However, there is no view associated with a receiver. One thing you can do is start the CometChatCallActivity from the Receiver and start the call from CometChatCallActivity.


1 Like

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