我有一个应用程序是SingleTask,并且可以监听“testing”计划。如果我点击按钮(参见代码),我会重新启动自己,并调用onNewIntent,从而给我提供“testing”意图(现在我可能通过推送片段来对其做出反应)。现在,如果我按下主页,然后打开应用程序启动器并重新进入我的应用程序,我希望onNewIntent被调用,但使用空意图,因为我不想重复我的操作(例如推送片段)。但是onNewIntent却给我上次用于启动我的活动的最后一个意图,即“testing”意图。我该怎么做才能防止推送相同的片段?有没有很好的方法可以使用而不使用我的自己的ID?
public class OnNewIntentTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.e("", "on create");
((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.e("", "Relaunch activity");
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("testing://hello")));
}
});
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.e("", "onNewIntent: " + (intent == null? "none" : (intent.getAction() + ":" + intent.getData())));
}
}