【问题标题】:Can a RemoteViews be passed in an Intent?可以在 Intent 中传递 RemoteViews 吗?
【发布时间】:2018-07-14 23:38:10
【问题描述】:

我正在尝试将 RemoteViews 传递给 intent,以便以后可以使用它来更新我的通知。但是,从 Intent 中获取 RemoteViews 时总是显示为 null。

基本上,单击按钮时,Notification 将减少或增加在通知中显示为textview 的权重值。

RemoteViews expandedView = new RemoteViews(context.getPackageName(), R.layout.remote_view_exercise_workout);
Intent addWeightIntent = new Intent(context, ExerciseWorkoutNotification.class);
addWeightIntent.putExtra("expandedView", expandedView);
expandedView.setOnClickPendingIntent(R.id.UpWeightButton, PendingIntent.getService(context, 1, addWeightIntent, PendingIntent.FLAG_UPDATE_CURRENT));

然后是意图处理:

protected void onHandleIntent(@Nullable Intent intent)  
RemoteViews expandedView = (RemoteViews) intent.getSerializableExtra("expandedView");
updateWeightNotification(workout, expandedView, workoutPosition, operator);

但是,我的扩展视图在 intentHandle 上总是显示为 null。

我做错了什么还是有更好的方法?

【问题讨论】:

    标签: android android-intent notifications


    【解决方案1】:

    试试

    RemoteViews expandedView = (RemoteViews) intent.getParcelableExtra("expandedView");
    

    编辑:由于RemoteViewsParcelable 的实现,上述解决方案应该可以工作。

    【讨论】:

    • 总是在答案中添加解释。就像问题需要明确一样,答案也需要明确。
    猜你喜欢
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多