Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Last active August 29, 2015 14:14
Show Gist options
  • Save SelvinPL/26264c9468830fcbde4e to your computer and use it in GitHub Desktop.
Save SelvinPL/26264c9468830fcbde4e to your computer and use it in GitHub Desktop.
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class TestActivity extends Activity {
//well context is not valid yet, but we will use later so it is ok to use "this"
private Helper helper = new Helper(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this method is using context ... but we are in onCreate so will work
helper.startBrowser();
}
private static class Helper {
Context mContext;
public Helper(Context context) {
mContext = context;
}
public void startBrowser() {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://google.com"));
mContext.startActivity(intent);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment