package com.gzz.whyinzi; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { private static final String TAG = "ActivityDemo"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse(http://www.jb51.net); intent.setData(content_url); startActivity(intent); } @Override protected void onResume() { super.onResume(); Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("http://play.jb51.net"); intent.setData(content_url); startActivity(intent); Log.e(TAG, "start onResume~~~"); } @Override protected void onStop() { super.onStop(); this.finish(); Log.e(TAG, "start onStop~~~"); } }
onResume()在沒有預設瀏覽器的時候就起作用了,當沒有預設瀏覽器的時候會彈出提示以哪個瀏覽器打開,如果點擊取消就會出現黑色背景,為防止出現黑色背景,onsume( )重新呼叫開啟瀏覽器.
onStop()在選擇瀏覽器後結束進程.
更多Android調用預設瀏覽器開啟指定Url的方法實例相關文章請關注PHP中文網!