0

In my app on OnCreate() method, I made a service; in the service,I made a thread in which I am starting a socket.

It seems ok with the flow : App runs , service starts -> thread starts -> socket starts and in thread , in while(true) loop I check socket for incoming data, when I received the specific data I will generate a notification. Notification fires but app crashes.

I gave the vibrate permission and introduced service to Androidmanifest file here is my notification code :

public void MakeNotification()
{
//      Intent intent = new Intent(this, MainActivity.class);
//      PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

    Notification notify = new Notification.Builder(this)
            .setContentTitle("Taxi Driver")
            .setContentText("New Mission")
            .setSmallIcon(R.drawable.ic_launcher)
            .setAutoCancel(true).build();
    notify.defaults |= Notification.DEFAULT_SOUND;
    notify.defaults |= Notification.DEFAULT_VIBRATE;
    NotificationManager notificationManager = (NotificationManager) 
              getSystemService(NOTIFICATION_SERVICE); 

    notificationManager.notify(0,notify);
    Toast.makeText(this, "clicked", Toast.LENGTH_SHORT).show();
}

Any information would be great. I have one assumption. is crashes happens because I made notification from another thread ??

Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
M.Armoun
  • 1,075
  • 3
  • 12
  • 38

1 Answers1

0

tthe problem solved.

based on this it's possible to fire a notification from another thread than UI.

so my problem was just calling Toast.makeText from a worker thread see

i removed it and it worked well

Community
  • 1
  • 1
M.Armoun
  • 1,075
  • 3
  • 12
  • 38