joy*_*nes 6 android android-intent launchmode
我有一个SingleTask应用程序,并能够听取'测试'方案.
如果我单击按钮(参见代码),我重新启动自己并调用onNewIntent给我'测试'意图(现在我可能通过推送片段对此作出反应)
现在,如果我按下主页,然后打开应用程序启动器并重新输入我的应用程序,我希望调用onNewIntent但是有一个空的意图,因为我不想重做我的行为(例如推送片段).但onNewIntent给了我用于启动我的活动的最后一个意图,即"测试"意图.
我该怎么做以防止推送相同的片段?没有使用我自己的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())));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1184 次 |
| 最近记录: |