如何打开片段页,当pressed在Android的通知 [英] How to open fragment page, when pressed a notification in android
问题描述
我想打开一个片段时,我preSS在通知栏的通知。我的应用程序的结构是:
I am trying to open a fragment when I press a notification in the notification bar. My app structure is:
- 与导航抽屉菜单基地活动
-
这是从菜单中打开某些片段
- a base activity with a nav drawer menu
some fragment that are opened from menu
b.setOnClickListener(新OnClickListener(){
b.setOnClickListener(new OnClickListener() {
@SuppressWarnings({ "deprecation", "static-access" })
public void onClick(View v) {
w_nm=(NotificationManager) getActivity().getSystemService(getActivity().NOTIFICATION_SERVICE);
Notification notify=new Notification(R.drawable.notnificationlogo,waternoti,System.currentTimeMillis());
Intent notificationIntent = new Intent(getActivity(), Abc.class);
PendingIntent pending=PendingIntent.getActivity(getActivity(), 0,notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP );
notify.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
notify.setLatestEventInfo(getActivity(),waternoti,waternoti1, pending);
w_nm.notify(0, notify);
谁能告诉我如何与一个碎片页面链接(在present code是在扩展片段级)
Can anyone tell me how to link with next fragment page (the present code is in class that extends fragment)
推荐答案
您需要开始你的基地的活动像往常一样,但增加了一些额外的信息,以意图是什么菜单片段将被打开。 在这里,你可以看到它是如何可以做到: http://stackoverflow.com/a/8610916/1652236
You need to start your base activity as usual, but add some extra info to intent about what menu fragment will be opened. Here you can see how it can be done: http://stackoverflow.com/a/8610916/1652236
和依赖于这些额外的信息,你可以在活动得到的onCreate()方法,你就可以开始特殊的片段。
And depends on this extra information which you can get in activity 'onCreate()' method, you can start special fragment.
在这里看到,例如如何使用碎片工作:<一href="http://www.tutorialspoint.com/android/android_fragments.htm">http://www.tutorialspoint.com/android/android_fragments.htm <一href="http://developer.android.com/guide/components/fragments.html">http://developer.android.com/guide/components/fragments.html
See here for example how work with fragments: http://www.tutorialspoint.com/android/android_fragments.htm http://developer.android.com/guide/components/fragments.html
这将是类似的东西:
Intent notificationIntent = new Intent(getActivity(), Abc.class);
notificationIntent.putExtra("menuFragment", "favoritesMenuItem");
及基础活动:
and in your base activity:
onCreate(...)
{
String menuFragment = getIntent().getStringExtra("menuFragment");
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (menuFragment != null)
{
if (menuFragment.equals("favoritesMenuItem"))
{
FavoritesFragment favoritesFragment = new FavoritesFragment();
fragmentTransaction.replace(android.R.id.content, favoritesFragment);
}
}
else
{
StandardFragment standardFragment = new StandardFragment();
fragmentTransaction.replace(android.R.id.content, standardFragment);
}
}
}
这样的情况下,如果你不把多余的,您将开始您惯常的标准片段,如果意图有多余的你会开始特别片段依赖于额外的信息。
so in case if you don't put extra, you will start your usual standard fragment, if intent has extra you will start special fragments depends on extra info.
这篇关于如何打开片段页,当pressed在Android的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!