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 ??