我一直在开发一个叫出租车的应用程序。在驱动程序的应用程序中,我有一个推送服务实例2活动,具体取决于推送内容。如果来自客户的呼叫启动活动1,如果选择了提取乘客的确认,则启动活动2。除了活动2可以按下各种按钮启动呼叫电话或活动3,但每次她拨打电话或活动三时返回活动1
我的清单看起来像:
<activity
android:label="@string/app_name"
android:name=".MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboardHidden|screenSize">
</activity>
<activity
android:label="@string/app_name"
android:name=".RouteActivity"
android:screenOrientation="portrait"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboardHidden|screenSize">
</activity>
我的推送服务;
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("MyTaxi")
.setContentText(msg)
.setUsesChronometer(true);
if(GlobalPersist.getGlobalPersist("tipoPush").equals("nueva")&& GlobalPersist.getGlobalPersist("carreraencurso").equals("false"))
{
Intent notIntent = new Intent(this, MainActivity.class);
MainActivity.from=1;
notIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(notIntent);
}
else if(GlobalPersist.getGlobalPersist("tipoPush").equals("cancelacion"))
{ GlobalPersist.getGlobalPersist("carreraencurso").equals("false");
Intent notIntent = new Intent(this, MainActivity.class);
MainActivity.from=1;
MainActivity.carreras.clear();
notIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
this.startActivity(notIntent);
}
else
{
Intent notIntent = new Intent(this, RouteActivity.class);
//MainActivity.from=1;
MainActivity.timer.cancel();
MainActivity.isTimerActivo=false;
notIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|
Intent.FLAG_ACTIVITY_SINGLE_TOP);
this.startActivity(notIntent);
}
调用startActivity()
后,只需调用finish()
即可。这将终止您的"活动",并允许您管理导航。