Why is the onNewIntent (intent intent) method called twice?

I am starting a new action with two parameters.

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); 

And catch the uri in onNewIntent .

 @Override public void onNewIntent(Intent intent) { //calls twice super.onNewIntent(intent); Uri uri = intent.getData(); new AsynkTask().execute(uri); } } 

But the onNewIntent method onNewIntent called twice for an unknown reason, which seems to be wrong.

+6
source share
2 answers
 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) 

In MainActivity;

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Bundle extras = getIntent().getExtras(); String url = extras.getString(url); } 

You can then parse the url and use it as a Uri. Thus, the method will not be called twice.

0
source

onNewIntent (intent intent) This is called for actions that set launchMode to "singleTop" in their package, or if the client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity (Intent).

If it is called twice, it should have been called unintentionally: starting the operation twice? Or is the method called manually?

0
source

All Articles