4

First!
Ok, so am working on a app "update system" for an application that is not hosted on the store. What I would like to do is launch the browser from an activity and then exit the application, leaving the browser open. Can this be done, and if so can you point me in the right direction?
Edit:
I dont know if this changes anything put I wish to do so from an AlertDialog.

BillHaggerty
  • 6,157
  • 10
  • 35
  • 68
  • i dont know exactly your requirements but you really dont need to open a browser to download the update apk from a server. – eldjon Jul 29 '14 at 14:46
  • Yes I know, but this is how i am doing it for now. Its just to make it prettier, and give the user some control while i am forcing a install. I might switch how it works later upon request. – BillHaggerty Jul 29 '14 at 14:56

2 Answers2

5

This is how you launch a browser:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.somewebsite.com"));
startActivity(browserIntent);

And this is how you finish your activity:

finish();

Finishing an activity is not the same as quitting your whole application, because there could be many activities in the stack. However, you can (and you should) leave this task to the system - your app's process will be killed automatically when there is not enough resources available. For reference: Quitting an application - is that frowned upon?

Edit: sample with AlertDialog:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Launch a website?");
builder.setPositiveButton(getString(R.string.yes),
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://www.somewebsite.com"));
            startActivity(browserIntent);
            finish();
        }
    }
);
builder.setNegativeButton(getString(R.string.no),
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            //some other thing to do
        }
    }
);

AlertDialog dialog = builder.create();
dialog.show();
Community
  • 1
  • 1
EyesClear
  • 28,077
  • 7
  • 32
  • 43
1

You need to create a new intent to open the browser on your device and finish the current activity after you have launched the new intent.

Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("http://www.google.com"));
startActivity(browserIntent);
finish();
Willie Nel
  • 363
  • 2
  • 9