하이브리드 앱 개발중에 어플종료 코드가 필요해서 아래 붉은 글씨처럼 종료를 할수 있도록 코드를 넣었습니다.
종료는 되지만 종료가 된후에 에러 창이 떠요....ㅠㅠ 혹시 몰라서 아래에 로그캣 첨부했구요..
다른 액티비티는 없어요..html 페이지라서요..
메니페스트에서도 추가하거나 삭제한 부분은 없는데 ㅠㅠ 도와주십쇼..ㅠㅠㅠ
에러 메세지는
the application testapp(process testapp.app.test)has stopped unexpectedly. please try again.
라고 뜹니다..ㅠㅠ
package testapp.app.test;
//import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.KeyEvent;
import org.apache.cordova.DroidGap;
public class testActivity extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
super.loadUrl("file:///android_asset/www/index.html");
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
new AlertDialog.Builder(this)
.setIcon(R.drawable.base)
.setTitle(R.string.app_name)
.setMessage("종료하시겠습니까?")
.setPositiveButton("종료", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
testActivity.this.finish();
}
})
.setNegativeButton("취소", null)
.show();
}
return true;
}
}
-----------------------------------------------------------------------------------------------------------------
06-29 12:06:40.510: E/AndroidRuntime(841): FATAL EXCEPTION: main
06-29 12:06:40.510: E/AndroidRuntime(841): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@40515088 is not valid; is your activity running?
06-29 12:06:40.510: E/AndroidRuntime(841): at android.view.ViewRoot.setView(ViewRoot.java:527)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.view.Window$LocalWindowManager.addView(Window.java:424)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.app.Dialog.show(Dialog.java:241)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
06-29 12:06:40.510: E/AndroidRuntime(841): at org.apache.cordova.CordovaChromeClient.onJsAlert(CordovaChromeClient.java:98)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:501)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.os.Looper.loop(Looper.java:123)
06-29 12:06:40.510: E/AndroidRuntime(841): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-29 12:06:40.510: E/AndroidRuntime(841): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 12:06:40.510: E/AndroidRuntime(841): at java.lang.reflect.Method.invoke(Method.java:507)
06-29 12:06:40.510: E/AndroidRuntime(841): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-29 12:06:40.510: E/AndroidRuntime(841): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-29 12:06:40.510: E/AndroidRuntime(841): at dalvik.system.NativeStart.main(Native Method)




return super.onKeyDown(keyCode, event);
이렇게 해보세요.