0

I am implementing calling functionality in my application with Twilio SDK. I am showing notification as soon as call starts, so the user can hang up the call from the notification bar. The problem is if user kills my application forcefully, I am not able to open the same calling activity from notification tray as my application is killed.

1: How can I detect if my app gets killed.

2: How Google play music notification works ( on click of notification it open the song detail activity - even though the application is killed).

3: How can I retain the same objects initialized at the time of creating the activity to disconnect the call.

duggu
  • 37,851
  • 12
  • 116
  • 113
sharma.mahesh369
  • 985
  • 11
  • 28

1 Answers1

1

Try this

Intent intent = new Intent(context, NotificationActivity.class);

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
                    .setContentTitle("title")
                    .setContentText("Test notification")
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(contentIntent)
                    .setPriority(NotificationCompat.PRIORITY_HIGH);

hope this help

Nirmal Prajapat
  • 1,735
  • 1
  • 12
  • 23
  • This will work only if app is in background. I app is killed from background forcefully it will not work – sharma.mahesh369 Feb 15 '18 at 12:38
  • on which api level you are testing this – Nirmal Prajapat Feb 15 '18 at 12:49
  • API 26, I checked WhatsApp on the same API and it works as expected. – sharma.mahesh369 Feb 15 '18 at 12:51
  • @sharma.mahesh I am facing the same issue. have you got the answer? Please help me. – Shailesh Jan 17 '20 at 06:32
  • How can I detect if my app gets killed? For this, I have bound the service and disconnected my call in onTaskRemoved method of Service as this method gets called if your app is killed forcefully or activity is closed. For the notification things I am creating a pending intent along with the data I required(Data required in activity) in case user click on notification tray and than I check whether I recive the data in onNewIntent(if already in stack) or in onCreate(if killed) – sharma.mahesh369 Jan 21 '20 at 06:52