我有一个应用程序,它有一个名为NfcScannerActivity的主菜单屏幕。目前,它在清单中没有启动模式(标准)。如果你点击getRota,它会将你带到rota屏幕,该屏幕在清单中定义为'singleTask‘,只是来自webcall的数据的列表视图。
在rota屏幕中,您可以从optionsMenu栏中单击nextRota。当这种情况发生时,将启动一个意图,指定菜单屏幕(NfcScannerActivity),因为这是进行webcall以获取第二天rota数据的位置。一旦检索到数据,就会再次启动rota屏幕。
所有这些都工作得很好,但我确信,由于任务中有多个菜单屏幕实例,应用程序中存在一些问题。如果我将NfcScannerActivity指定为'SingleTask‘,那么当你点击next rota时,它会停留在菜单屏幕上,就好像它还没有处理"NEXT_ROTA“意图操作一样。
我知道我可能需要在NfcScannerActivity活动中重写onNewIntent。
这是怎么做的?我已经尝试了以下几种方法。
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}。
这似乎不能处理“NEXT_ROTA”意图操作。谢谢,马特。
edit1
这是当用户单击options菜单中的next_rota时,我在rota活动中看到的内容。
Intent i = new Intent(this, NfcscannerActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra("nextRota", nextDay);
i.setAction("NEXT_ROTA");
startActivity(i);。
然后,在NfcScannerActivity的onCreate中,我有以下内容。
if(intent.getAction().equalsIgnoreCase("NEXT_ROTA")){
Log.e(TAG, "next rota action");
String date = intent.getStringExtra("nextRota");
getNextRota(date);
}。
getNextRota(date)调用一个AsyncTask来进行get调用,以获取下一个rota的数据。在onPostExecute中,它执行以下操作。
Intent intent = new Intent(NfcscannerActivity.this,
GetRota.class);
Bundle b = new Bundle();
b.putSerializable("rotaArray", rotaArray);
intent.putExtra("rotaArrayBundle", b);
startActivity(intent);。
所以我已经在处理onCreate内部NfcScannerActivity中的'NEXT_ROTA‘意图操作了。我必须在onNewIntent中做同样的事情吗?
发布于 2013-07-17 17:08:28
请尝试以下操作
在rota screen活动中,当“一个意图被启动,指定菜单屏幕”
Intent intent = new Intent(<rota screen activity>, NfcScannerActivity.class);
intent.setAction("NEXT_ROTA");
//this brings the previous existing activity to the front of the stack
//instead of creating a new one
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);在NfcScannerActivity中
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent.getAction().equals( "NEXT_ROTA")){
String date = intent.getStringExtra("nextRota");
getNextRota(date);
}
}上面应该做的是允许您创建任意多个Rota屏幕,但只有一个NfcScannerActivity
https://stackoverflow.com/questions/17695349
复制相似问题