在android開發中有時候會用到一些後臺的Activity,但又不適合使用service。例如程序圖標直接進入指定的網址,不需要彈出程序界面。
此時可以在項目的AndroidManifest.xml文件中相應的Activity標籤中添加這樣一行:
android:theme="@android:style/Theme.NoDisplay"
並在對應的Activity中實現:
@Override
protected void onPause() {
super.onPause();
finish();
}
PS:訪問指定網址的方法
1.指定網址並指定瀏覽器訪問
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("http://www.baidu.com");
intent.setData(content_url);
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
startActivity(intent);
2.指定網址並按默認瀏覽器訪問:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.jieig.com/main.html"));
startActivity(intent);
•android:theme="@android:style/Theme.Dialog"
將一個Activity顯示爲能話框模式
•android:theme="@android:style/Theme.NoTitleBar" 不顯示應用程序標題欄
•android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不顯示應用程序標題欄,並全屏
•android:theme="Theme.Light" 背景爲白色
•android:theme="Theme.Light.NoTitleBar" 白色背景並無標題欄
•android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,無標題欄,全屏
•android:theme="Theme.Black" 背景黑色
•android:theme="Theme.Black.NoTitleBar" 黑色背景並無標題欄
•android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,無標題欄,全屏
•android:theme="Theme.Wallpaper" 用系統桌面爲應用程序背景
•android:theme="Theme.Wallpaper.NoTitleBar" 用系統桌面爲應用程序背景,且無標題欄
•android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系統桌面爲應用程序背景,無標題欄,全屏
•android:theme="Translucent"
•android:theme="Theme.Translucent.NoTitleBar"
•android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
•android:theme="Theme.Panel"
•android:theme="Theme.Light.Panel"
詳細介紹