Proper Android Intent Helper Class Usage?
I have two classes a MainActivity.class and a IntentsUtils.class.
Here is my IntentsUtils.class:
public class IntentsUtils
{
public void invokeWebBrowser(Activity activity)
{
String url = "http://snipt.net/Martin/android-intent-usage/";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
activity.startActivity(intent);
}
开发者_JAVA技巧 }
If I wanted to run invokeWebBrowser() from my MainActivity.class, what would be the best method?
Thanks.
Button button = (Button) findViewById(R.id.launch_br_btn);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick() {
IntentUtils.invokeWebBrowser(MainActivity.this);
}
})
put this to your onCreate()
method of MainActivity.
精彩评论