首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TaskStackBuilder -向后兼容还是不兼容?

TaskStackBuilder -向后兼容还是不兼容?
EN

Stack Overflow用户
提问于 2014-05-01 19:25:12
回答 1查看 506关注 0票数 1

我正在按照示例这里设置一个通知。我的应用程序兼容API 15和别有用心的版本。这是我的密码:

代码语言:javascript
复制
@Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        // send notification

        // API < 16 so have to use compat
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                //.setSmallIcon(context.getResources().getDrawable(icon_id_here))
                .setContentTitle("My notification")
                .setContentText("Hello World!");
        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(context, UpcomingTest.class);

        // The stack builder object will contain an artificial back stack for the
        // started Activity.
        // This ensures that navigating backward from the Activity leads out of
        // your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(UpcomingTest.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // mId allows you to update the notification later on.
        mNotificationManager.notify(123, mBuilder.build());

    }

当阅读有关TaskStackBuilder的信息时,它说:"TaskStackBuilder提供了一种向后兼容的方式,可以在设备版本的平台上遵守有关跨任务导航的正确约定。“但是,我得到了一个错误,该错误说,为了使用TaskStackBuilder,我需要瞄准最小的API 16。我还需要做些什么才能真正做到向后兼容呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-01 19:28:52

您可能正在导入android.app.TaskStackBuilder而不是android.support.v4.app.TaskStackBuilder --检查您的导入。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23415013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档