Android 如何从服务调用活动的onNewIntent()
如何从服务执行活动的onNewIntent()?触发意图时要给出什么标志???您不能自行调用Android 如何从服务调用活动的onNewIntent(),android,android-intent,Android,Android Intent,如何从服务执行活动的onNewIntent()?触发意图时要给出什么标志???您不能自行调用onNewIntent,系统将调用它。如果您的活动可以处理激发的意图,那么它将被自动调用,请检查您的意图和相关的意图过滤器 只有当您的活动是单顶的并且您的活动的Oncreate已被调用时,才会调用此函数。您不能自行调用onNewIntent,系统将调用它。如果您的活动可以处理激发的意图,那么它将被自动调用,请检查您的意图和相关的意图过滤器 只有当您的活动是单顶的并且已经调用了活动的Oncreate时,才会
onNewIntent
,系统将调用它。如果您的活动可以处理激发的意图,那么它将被自动调用,请检查您的意图和相关的意图过滤器
只有当您的活动是单顶的并且您的活动的Oncreate已被调用时,才会调用此函数。您不能自行调用
onNewIntent
,系统将调用它。如果您的活动可以处理激发的意图,那么它将被自动调用,请检查您的意图和相关的意图过滤器
只有当您的活动是单顶的并且已经调用了活动的Oncreate时,才会调用此方法。如果要执行某些操作,则必须重写此方法 以通知为例
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(com.example.xyz.R.drawable.ic_launcher,message1, when);
Intent notificationIntent = new Intent(context,com.example.xyz.DemoActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("MESSAGE",pkgName);
notificationIntent.putExtra("APP_STATUS", AppStatus);
notificationIntent.putExtra("APP_NAME",AppName);
//PendingIntent.FLAG_UPDATE_CURRENT will update the notification
PendingIntent intent=PendingIntent.getActivity(context, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT );
notification.setLatestEventInfo(context, title, message1, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
我的DemoActivity.class看起来像
public class DemoActivity extends Activity{
public static String BROADCAST_ACTION = "com.example.android.APP_CLOUD_DELETE_APK";
private TextView messsageText,NotificationHeader;
private Button okButton;
private int AppStatusId;
private String PkgName,app_name,ApkFileName;
private RegisterTask mRegisterTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_activity);
// if this activity is not in stack , this mwthod will be called
}
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
// if this activity is in stack , this mwthod will be called
}
如果要执行某些操作,必须重写此方法 以通知为例
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(com.example.xyz.R.drawable.ic_launcher,message1, when);
Intent notificationIntent = new Intent(context,com.example.xyz.DemoActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("MESSAGE",pkgName);
notificationIntent.putExtra("APP_STATUS", AppStatus);
notificationIntent.putExtra("APP_NAME",AppName);
//PendingIntent.FLAG_UPDATE_CURRENT will update the notification
PendingIntent intent=PendingIntent.getActivity(context, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT );
notification.setLatestEventInfo(context, title, message1, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
我的DemoActivity.class看起来像
public class DemoActivity extends Activity{
public static String BROADCAST_ACTION = "com.example.android.APP_CLOUD_DELETE_APK";
private TextView messsageText,NotificationHeader;
private Button okButton;
private int AppStatusId;
private String PkgName,app_name,ApkFileName;
private RegisterTask mRegisterTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_activity);
// if this activity is not in stack , this mwthod will be called
}
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
// if this activity is in stack , this mwthod will be called
}
我需要在意向过滤器中提供一些信息吗?我需要在意向过滤器中提供一些信息吗??