phonegap在android中如何退出程序
這個問題有兩個解決辦法,第一用android在mainActiviy中寫一段,第二用phonegap的自帶接口
一、核心是方法System.exit(0);,因為finish()啥的都不能用
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);?
super.loadUrl("file:///android_asset/www/index.html");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
promptExit(this);
return true;
}
return super.onKeyDown(keyCode, event);
}
public static void promptExit(final Context con) {
LayoutInflater li = LayoutInflater.from(con);
View exitV = li.inflate(R.layout.exitdialog, null);
AlertDialog.Builder ab = new AlertDialog.Builder(con);
ab.setView(exitV);// 設(shè)定對話框顯示的View對象
ab.setPositiveButton("退出",
new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
System.exit(0);
}
});
ab.setNegativeButton("取消", null);
// 顯示對話框
ab.show();
}
}
二 在js中寫
?//添加回退按鈕事件
? ? ? ? document.addEventListener("backbutton",onBackKeyDown,false);
? ? ? ? //BackButton按鈕
? ? ? ? function onBackKeyDown(){
? ? ? ? ? ? if($.mobile.activePage.is('#homepage')){
? ? ? ? ? ? ? ? navigator.app.exitApp();
? ? ? ? ? ? }
? ? ? ? ? ? else {
? ? ? ? ? ? ? ? navigator.app.backHistory();
? ? ? ? ? ? }
? ? ? ? }
轉(zhuǎn)載于:https://my.oschina.net/liangzhenghui/blog/401828
總結(jié)
以上是生活随笔為你收集整理的phonegap在android中如何退出程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux6安装图形化界面,centos
- 下一篇: 解析mediaTypes+viewRes