hi. this is my code for local in app notification.
but the background service is not working properly for more than one notification at a time in a session. this also deletes my previous notification and the latest ones are displayed when i try it.
ExampleService.js
var service = Ti.Android.currentService; var serviceIntent = service.getIntent(); var timestamp = new Date(serviceIntent.getStringExtra('timestamp')); if (new Date() > timestamp) { // Grab extra data sent with the intent var title = serviceIntent.getStringExtra('title'); var message = serviceIntent.getStringExtra('message'); // Create an intent that launches the application var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, packageName: 'com.mycompany.myapp' }); intent.flags |= Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP; intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); // Create notification var notification = Ti.Android.createNotification({ contentIntent : Ti.Android.createPendingIntent({intent : intent}), contentTitle : title, contentText : message, }); notify_id = 1; // Send the notification // notify_id is dynamically generated for multiple notifications; Ti.Android.NotificationManager.notify(notify_id, notification); // Stop the service once the notification is sent Ti.Android.stopService(serviceIntent); }
index.js
var intent = Ti.Android.createServiceIntent({ url : 'ExampleService.js' }); intent.putExtra('title' , 'Richard III'); intent.putExtra('message' , 'Now is the winter of our discontent...'); intent.putExtra('timestamp', new Date(new Date().getTime() + 30 * 1000)); Ti.Android.startService(intent);
please help me out for the same.