public class MyBroadcastReceiver extends BroadcastReceiver
{
public boolean checkApp;
@Override
public void onReceive(Context context, Intent intent)
{
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName
.equals("-------> Ur package ----> example--[com.emdsys.android.pacs]")) {
List<ActivityManager.RunningTaskInfo> taskInfo = activityManager
.getRunningTasks(1);
if (taskInfo.get(0).topActivity
.getClassName()
.toString()
.equals("-----> UR Activity Name-------(-ex)[com.emdsys.android.pacs.activity.TabActivityPacs]")) {
checkApp = true;
//update ur activity what ever u want.
}
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName();
}
}
if(!checApp){
Log.d("ME", "Notification started");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, [ur Activity].class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
setContentIntent(contentIntent).build();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
您是否檢查過[此鏈接](http://stackoverflow.com/questions/5446565/android-how-do-i-check-if-activity-is-running) – 2014-09-25 08:20:29