Android onNewIntent from app launches latest intent

Im has an application that is SingleTask and can listen to the testing scheme.

If I press the button (see code), I restarted myself, and onNewIntent is called, giving me the intention of β€œtesting” (now I can respond to this by clicking on the snippet)

Now, if I click on the house and then open the application and restart the application, I would like onNewIntent to be called, but with an empty intention, because I do not want to repeat my actions (for example, clicking fragments). But onNewIntent gives me the last intention that was used to start my activity, which is the purpose of testing.

What should I do to prevent clicking the same fragment? Is there a good way without using my own identifiers.

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()))); } } 
+6
source share
1 answer

setIntent (zero); after receiving the data you need in onNewIntent

0
source

Source: https://habr.com/ru/post/908054/


All Articles