Zxing处理后退按钮

时间:2012-11-24 23:06:38

标签: android android-intent zxing

如果用户从我的应用程序(意图)启动Zxing条形码扫描程序而不是按回按钮,我该怎么办? - 它显示“对不起MyApp被迫关闭”(或多或少,因为我的语言不是英语)。 现在我有:

if (scanResult != null) {
          intent.putExtra("com.tajchert.kolejrogowska.SCAN.SCAN_MODE", "QR_CODE_MODE");
          String contents = intent.getStringExtra("SCAN_RESULT");
          whatToDo(contents);
      }
      else{
          finish();
      }

没有else{}阻止它是一样的。

编辑:记录:

11-25 00:16:33.738: E/AndroidRuntime(21969): FATAL EXCEPTION: main
11-25 00:16:33.738: E/AndroidRuntime(21969): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=49374, result=0, data=null} to activity {com.tajchert.kolejrogowska/com.tajchert.kolejrogowska.Kody}: java.lang.NullPointerException
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.access$2800(ActivityThread.java:125)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.os.Looper.loop(Looper.java:123)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.main(ActivityThread.java:4627)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at java.lang.reflect.Method.invokeNative(Native Method)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at java.lang.reflect.Method.invoke(Method.java:521)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at dalvik.system.NativeStart.main(Native Method)
11-25 00:16:33.738: E/AndroidRuntime(21969): Caused by: java.lang.NullPointerException
11-25 00:16:33.738: E/AndroidRuntime(21969):    at com.tajchert.kolejrogowska.Kody.onActivityResult(Kody.java:77)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.Activity.dispatchActivityResult(Activity.java:3890)
11-25 00:16:33.738: E/AndroidRuntime(21969):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
11-25 00:16:33.738: E/AndroidRuntime(21969):    ... 11 more

1 个答案:

答案 0 :(得分:4)

输入:

if (scanResult != null) {
    String contents = scanResult.getContents();
    if(contents != null)
        whatToDo(contents);
    else
        finish();
}