navigator.app.exitApp()在phonegap 3.1.0上崩溃了

时间:2014-01-09 08:07:58

标签: android cordova

每次在我的应用程序中调用navigator.app.exitApp()时,应用程序都会崩溃。请在我收到的崩溃日志下面找到。

01-09 13:20:24.556: E/AndroidRuntime(18767): FATAL EXCEPTION: main
01-09 13:20:24.556: E/AndroidRuntime(18767): java.lang.RuntimeException: Unable to       destroy activity {com.pixatel.mathwhiz/com.pixatel.mathwhiz.MathWhiz}:   java.lang.IllegalArgumentException: Receiver not registered: null
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3294)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3312)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.ActivityThread.access$1200(ActivityThread.java:138)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.os.Looper.loop(Looper.java:213)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.ActivityThread.main(ActivityThread.java:4787)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at java.lang.reflect.Method.invokeNative(Native Method)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at java.lang.reflect.Method.invoke(Method.java:511)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at dalvik.system.NativeStart.main(Native Method)
01-09 13:20:24.556: E/AndroidRuntime(18767): Caused by: java.lang.IllegalArgumentException: Receiver not registered: null
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:654)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1165)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:378)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at org.apache.cordova.device.Device.onDestroy(Device.java:98)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at org.apache.cordova.PluginManager.onDestroy(PluginManager.java:326)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at org.apache.cordova.CordovaWebView.handleDestroy(CordovaWebView.java:833)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at org.apache.cordova.CordovaActivity.onDestroy(CordovaActivity.java:774)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.Activity.performDestroy(Activity.java:5172)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1109)
01-09 13:20:24.556: E/AndroidRuntime(18767):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3281)

以下代码是我的主要活动文件: -

public class MathWhiz extends CordovaActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());

        //super.loadUrl("file:///android_asset/www/index_android.html");

        try {
            String pName = this.getClass().getPackage().getName();
            this.copy("Databases.db", "/data/data/" + pName + "/app_database/");
            this.copy("0000000000000001.db", "/data/data/" + pName
                    + "/app_database/file__0/");
        } catch (IOException e) {
            e.printStackTrace();
        }

       // super.loadUrl("file:///android_asset/www/index_android.html",3000);
    }

    void copy(String file, String folder) throws IOException {

        File CheckDirectory;
        CheckDirectory = new File(folder);
        if (!CheckDirectory.exists()) {
            CheckDirectory.mkdir();
        }

        InputStream in = getApplicationContext().getAssets().open(file);
        OutputStream out = new FileOutputStream(folder + file);

        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0)
            out.write(buf, 0, len);
        in.close();
        out.close();

这个问题在phonegap版本2.9.0中没有出现。开始发生3.1.0。 请告诉我与之相关的问题。提前谢谢。

1 个答案:

答案 0 :(得分:2)

根据file,设备插件注册接收器以侦听电话操作。因此,请确保您已添加所需的权限,以使Telephony在Android.Manifest.xml文件中正常工作。