PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SayHello.class), Intent.FLAG_ACTIVITY_NEW_TASK); // The ticker text, this uses a formatted string so our message could be // localized String tickerText = getString(R.string.imcoming_message_ticker_text, message); // construct the Notification object. Notification notif = new Notification(R.drawable.icon, tickerText, System.currentTimeMillis()); // Set the info for the views that show in the notification panel. notif.setLatestEventInfo(this, from, message, contentIntent);但是每次new Intent(this, SayHello.class)会新建一个activity,同一个页面有两个。 怎么才能在点击通知图标,切换到前台后,只显示原来的主界面呢? 而不是重新创建一个主界面。
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, SayHello.class), Intent.FLAG_ACTIVITY_NEW_TASK); // The ticker text, this uses a formatted string so our message could be
// localized
String tickerText = getString(R.string.imcoming_message_ticker_text,
message); // construct the Notification object.
Notification notif = new Notification(R.drawable.icon, tickerText,
System.currentTimeMillis()); // Set the info for the views that show in the notification panel.
notif.setLatestEventInfo(this, from, message, contentIntent);但是每次new Intent(this, SayHello.class)会新建一个activity,同一个页面有两个。
怎么才能在点击通知图标,切换到前台后,只显示原来的主界面呢?
而不是重新创建一个主界面。
通过在androidManifest写入一个
<receiver android:name=".BootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
可以实现开机自动登录。
但通过程序的方式取消开机自动登录呢,在程序中可以在androidManifest中添加/删除属性吗?
今天没分了,还望过路英雄指点一下
然后设置那个activity是single task的
我已经给出解决方案了,可能不是太好!难道不是同一个人?
设置Intent.FLAG_ACTIVITY_NEW_TASK,打开notification确实还会新建一个activity
可以这样,把notification的跳转指向一个activity,这个activity什么也不做,在oncreate里面写一个finish();这样就OK了
而在程序中手工注册广播。可以否??
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(ACTION))
{
if(ConfigManager.Instance(context).loadBoolean("runAuto")) {
Intent sayHelloIntent = new Intent(context, ChannelMainActivity.class);
sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(sayHelloIntent);
}
}
}