Back to project page android_tutorial_projects.
The source code is released under:
Copyright (c) 2013, Uthcode All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redi...
If you think the Android project android_tutorial_projects listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.uthcode.lifecycleactivity; /*w ww.ja v a 2 s.c om*/ import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.os.Bundle; public class TracerActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); notify("onCreate"); } @Override protected void onPause() { super.onPause(); notify("onPause"); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); notify("onSaveInstanceState"); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); notify("onRestoreInstanceState"); } @Override protected void onDestroy() { super.onDestroy(); notify("onDestroy"); } @Override protected void onStop() { super.onStop(); notify("onStop"); } @Override protected void onResume() { super.onResume(); notify("onResume"); } private void notify(String methodName) { String name = this.getClass().getName(); String[] strings = name.split("\\."); Notification noti = new Notification.Builder(this) .setContentTitle(methodName + "" + strings[strings.length - 1]) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_launcher) .setContentText(name).build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify((int) System.currentTimeMillis(), noti); } }