3 回答
TA贡献2019条经验 获得超9个赞
从通知中返回/发送数据到您的原始活动;上面的示例所需的更改:
NotificationPanel nPanel = new NotificationPanel(MyActivity)
如何使用通知按钮来恢复与创建通知相同的堆栈和活动:
1)确保“活动”未销毁(可选),更改“后退”按钮以将任务放在后面,但不要销毁它:
@Override
void onBackPressed() {
Log.d("onBackPressed", "onBackPressed Called");
moveTaskToBack(true);
}
2)在清单中,将其添加到活动中:
android:launchMode="singleTop"
3)为您的Intent实例添加这些标志:(volume是Intent实例)
Intent volume = new Intent(....);
....
volume.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
volume.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
并且您还可以添加以下内容(可选):
volume.setAction(Intent.ACTION_MAIN);
volume.addCategory(Intent.CATEGORY_LAUNCHER)
4)在PendingIntent实例中,不要使用任何标志:
PendingIntent btn1 = PendingIntent.getActivity(parent, 0, volume, 0);
5)并通过onNewIntent(Intent intent)回调来捕获您的Activity中的意图:
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
super.onNewIntent(intent);
setIntent(intent);
Log.i("onNewIntent", intent.toString()); // DEBUG - very useful
if (intent.getExtras() != null) { // As the Intent we send back has extras, if it don't, it is a different Intent. it is possible to use TRY {} CATCH{} for this as well to find if Extras is NULL.
String tmp;
tmp = intent.getExtras().getString("DO");
if (tmp != null) {
if (tmp.equals("volume"))
Log.i("onNewIntent", "Volume");
else if (tmp.equals("stop"))
Log.i("onNewIntent", "Stop");
else
Log.i("onNewIntent", "Didnt capture the extras of the Intent - " + tmp);
} else {
Log.i("onNewIntent", "No new Intent");
}
}
}
- 3 回答
- 0 关注
- 473 浏览
添加回答
举报