在我的应用程序中,我使用IntentService
类在后台启动另一个活动.但我得到的问题是,从IntentService
课程开始,我开始我的活动,打开我的活动,之后我不关闭我的活动.然后我注意到,当IntentService
类再次想要开始我的同一活动时,它不被调用,因为相同的活动不是关闭的.所以我的问题是我怎样才能一次又一次地开始相同的活动,无论是开课还是近IntentService
课.
IntentService类中的代码
public class AlarmService extends IntentService
{
public void onCreate() {
super.onCreate();
}
public AlarmService() {
super("MyAlarmService");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, startId, startId);
return START_STICKY;
}
@Override
protected void onHandleIntent(Intent intent) {
startActivity(new Intent(this,
AlarmDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
Run Code Online (Sandbox Code Playgroud)
在清单文件中使用launchMode标记
<activity
android:name=".ActivityName"
android:launchMode="singleTask" />
Run Code Online (Sandbox Code Playgroud)
如果已经可用,它将不会创建不同的活动实例.
请参阅此链接launchMode以便更好地理解
归档时间: |
|
查看次数: |
2885 次 |
最近记录: |