通知空白我的活动

时间:2015-06-15 12:03:15

标签: android notifications

如果有新闻并且用户没有使用我的应用程序,我会发出通知弹出通知...当用户触摸通知时,我希望它将它们带到主页面上,并且我使用PendingIntent声明它... 但是,我的应用程序并没有显示任何片段,尽管它们是可见的而不是隐藏的。 这是我用来显示通知的代码

Intent inte = new Intent(this, HomeActivity.class);
                    PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, inte, PendingIntent.FLAG_UPDATE_CURRENT);

                    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
                            .setContentTitle(getString(R.string.app_name))
                            .setContentText(getString(R.string.notification_text))
                            .setContentIntent(pIntent)
                            .setAutoCancel(true);

                    NotificationManager man = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                    man.notify(0,builder.build());

这是我的onCreate。我认为它与我的SaveInstanceState有关,但无法理解。 我的onCreate仅在没有保存实例状态时才添加片段,然后显示或隐藏一些片段。

super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
        if (savedInstanceState == null) {
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.add(R.id.fragment_left,mChatListFragment);
            transaction.add(R.id.fragment_left,mQuestionListFragment);
            transaction.hide(mQuestionListFragment);
            transaction.show(mChatListFragment);
            if (findViewById(R.id.fragment_right) != null) {    // two pane layout
                transaction.add(R.id.fragment_right,mChatDetailsFragment);
                transaction.add(R.id.fragment_right,mChatNewFragment);
                transaction.add(R.id.fragment_right,mQuestionDetailsFragment);
                transaction.add(R.id.fragment_right,mQuestionNewFragment);
                transaction.hide(mQuestionDetailsFragment);
                transaction.show(mChatNewFragment);
                transaction.hide(mChatDetailsFragment);
                transaction.hide(mQuestionNewFragment);
            }
            else {
                transaction.add(R.id.fragment_left,mChatDetailsFragment);
                transaction.add(R.id.fragment_left,mChatNewFragment);
                transaction.add(R.id.fragment_left,mQuestionDetailsFragment);
                transaction.add(R.id.fragment_left,mQuestionNewFragment);
                transaction.hide(mQuestionDetailsFragment);
                transaction.hide(mChatNewFragment);
                transaction.hide(mChatDetailsFragment);
                transaction.hide(mQuestionNewFragment);
            }
            transaction.commit();
        }

0 个答案:

没有答案