Android ouverture onglet spécifique fragment de notification, cliquez sur

J'ai une application android qui utilise l'Action de la Barre des Onglets. Il y a aussi un système de notification.

Je veux ouvrir un onglet spécifique directement, en cliquant sur la notification. Comment ce faire(parce que la notification en attendant les intentions ne peuvent ouvrir activités, et mon activité principale contient 3 fragments de 3 onglets) ?

Voici le code pour le mainactivity pour les onglets.

    public class MaintabActivity extends Activity {
public static Context appContext;
public static MapView mMapView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainsc);
appContext = getApplicationContext();
startService(new Intent(this, MyService.class));
//ActionBar
ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab ChatTab = actionbar.newTab().setText("Chat");
ActionBar.Tab MapsTab = actionbar.newTab().setText("Maps");
ActionBar.Tab SplashTab=actionbar.newTab().setText("Splash");
Fragment ChatFrag = new ChatActivity();
MapActivity mMapFragment = MapActivity.newInstance();
Fragment SplashFrag = new SplashActivity();
ChatTab.setTabListener(new MyTabsListener(ChatFrag));
MapsTab.setTabListener(new MyTabsListener(mMapFragment));
SplashTab.setTabListener(new MyTabsListener(SplashFrag));
actionbar.addTab(ChatTab);
actionbar.addTab(MapsTab);
actionbar.addTab(SplashTab);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
}
}
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment) {
this.fragment = fragment;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(MaintabActivity.appContext, "Reselected!", Toast.LENGTH_LONG).show();
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
}
}

C'est le code du service qui montre la notification.

    private void showNotification() {
CharSequence text = getText(R.string.local_service_started);
//Set the icon, scrolling text and timestamp
Notification notification = new Notification(R.drawable.ic_launcher, text,
System.currentTimeMillis());
//The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MaintabActivity.class), 0);
//Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(this, getText(R.string.local_service_label),
text, contentIntent);
//Send the notification.
mNM.notify(NOTIFICATION, notification);
}
un peu de code.
Code pour quoi ? Son examen régulier de l'action de la barre des onglets, et je veux ouvrir supposons que la languette B en cliquant sur la notification.
user2319636-lorsque vous cliquez sur la notification d'appeler votre activité contenant des Onglets et vous pouvez appeler votre fragment spécifique dans viewPager par ce--viewPager.setCurrentItem(position);
Que faire si il ya 2 différents types de notifications, et je veux ouvrir plusieurs onglets ? Comment l'activité de savoir à laquelle la notification a été cliqué ?
que vous pouvez passer les Onglets position avec notification...de sorte que, lorsque l'activité d'être appelé, il sera affiché en fonction de la position du fragment dans la vue Pager..poster du code, de sorte que je peux vous aider.

OriginalL'auteur user2319636 | 2013-05-04