I'm new to android.i create a service to show a notification when onCreat on mainActivity is called
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent a = new Intent(this,myService.class); startService(a); } }
here is my class of service
public class myService extends Service{ private NotificationManager mManager; @Override public void onCreate() { mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE); Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class); Notification notification = new Notification(R.drawable.ic_launcher,"This is a test message!", System.currentTimeMillis()); intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this.getApplicationContext(), "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent); mManager.notify(0, notification); }
but I want, if my application does not work, I can show this service, for example, if my phone time is more than 9, I show this notification only once a day. thank you in advance
user2768684
source share