Reputation: 123
How to execute onNewIntent() of Activity from a sevice? What are flags to be given while firing the intent??
Upvotes: 2
Views: 6238
Reputation: 1698
You will have to override this method if you want to do some thing for notification as an example
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);
and my DemoActivity.class looks likes
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
}
Upvotes: 1
Reputation: 1969
You cannot call onNewIntent
by self it'll called by the system. If your activity can handle fired intent then it will be called automatically, check your intent and related intent filter.
This is only called when you activity is singletop and your activity's Oncreate has already been called.
Upvotes: 3