Launch another app, then go back to the previous app and it will change to the next page.

I would like my application to be able to navigate to another application by clicking a button with the following code:

public void go_other_app() {
        Button going= (Button) findViewById(R.id.go_to_other);

        going.setOnClickListener(new OnClickListener() {

            @Override

            public void onClick(View view) {

                Intent launchIntent = getPackageManager().getLaunchIntentForPackage("package name");
                if (launchIntent==null){
                    Toast.makeText(getApplicationContext(), "You haven't installed this app yet!", Toast.LENGTH_SHORT).show();
                }else{
                    startActivity(launchIntent);

                }
            }

        });

    }

      

Then, when the user finishes the material in this additional application, he is asked to leave it and go back. But I would like him to immediately switch to another activity without leaving the same activity. I only know a way to start a new activity:

Intent i=new Intent(getBaseContext(),another_activity.class);
                    startActivity(i);

      

So, is this a good way to accomplish my task? Many thanks!

+3


source to share


1 answer


From your FirstActivity

call SecondActivity

with the methodstartActivityForResult()

For example:

Intent i = new Intent(this, SecondActivity.class);
startActivityForResult(i, 2404);

      

When the user hits the back button, it will notify the onActivityResult

method FirstActivity

.



Enter the following code for firstActivty.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 2404) {
        Intent i=new Intent(getBaseContext(),another_activity.class);
        startActivity(i);
    }
}

      

For more information see below link.
1. startActivity
1. startActivityForResult
2. onActivityResult

+3


source







All Articles