我用两个参数开始一个新活动.
Intent intent = new Intent(WebTestActivity.this,MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); Uri uri = Uri.parse(url); intent.setData(uri); startActivity(intent);
并在onNewIntent方法中捕获uri.
@Override public void onNewIntent(Intent intent) { //calls twice super.onNewIntent(intent); Uri uri = intent.getData(); new AsynkTask().execute(uri); } }
解决方法
Intent intent = new Intent(WebTestActivity.this,MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("url",url); startActivity(intent)
在MainActivity中;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Bundle extras = getIntent().getExtras(); String url = extras.getString(url); }