当您通过硬件后退按钮关闭意图时,这会冻结应用程序

时间:2014-06-03 16:33:18

标签: android delphi android-intent zxing delphi-xe6

我使用Delphi XE6创建了一个Android应用程序,并使用互联网上的代码连接到ZXing BarCode Scanner。

在只使用此代码的新项目中,一切正常!

如果我添加了多个TabControlToolBarLabelEditButton和其他标准组件,我就会发生这种情况:

  1. ZXing正常启动,如果我定期将条形码扫描回我的应用程序。
  2. 如果我使用硬件后退按钮关闭ZXing,ZXing会关闭,但应用程序会被黑屏冻结。
  3. 通过调试,应用程序似乎没有停止。返回代码已更正,流程一直持续到结束,不会出现任何错误。

    主叫代码是:

    function TZXing.ZXingScan: Boolean;
    var
      Intent: JIntent;
      ResolveInfo: JResolveInfo;
    begin
      Intent := TJIntent.JavaClass.init( StringToJString( 'com.google.zxing.client.android.SCAN' ) );
      Intent.setPackage( StringToJString( 'com.google.zxing.client.android' ) );
      Intent.putExtra( StringToJString( 'SAVE_HISTORY' ), False );
      ResolveInfo := SharedActivity.getPackageManager.resolveActivity( Intent, 0 );
      Result := ResolveInfo <> nil;
      if Result then
        SharedActivity.startActivityForResult( Intent, 0 );
    end;
    

    回调程序代码为:

    procedure TZXing.OnZXingResult( RequestCode, ResultCode: Integer; Data: JIntent );
    begin
      TMessageManager.DefaultManager.Unsubscribe( TMessageResultNotification, FMessageSubscriptionID );
      FMessageSubscriptionID := 0;
      if ( RequestCode = 0 ) and Assigned( FResultProcedure ) then
      begin
        if ResultCode = TJActivity.JavaClass.RESULT_OK then
        begin
          if Assigned( Data ) then
            Result := ( OK, JStringToString( Data.getStringExtra( StringToJString( 'SCAN_RESULT_FORMAT') ) ), JStringToString( Data.getStringExtra( StringToJString( 'SCAN_RESULT' ) ) ) )
          else
            Result := ERROR;
        end else if ResultCode = TJActivity.JavaClass.RESULT_CANCELED then
          Result := CANCELED;
      end;
    end;
    

    我已经尝试了所有的东西并尝试了一切,但我找不到解决方案。

2 个答案:

答案 0 :(得分:0)

最有可能的是,您的结果代码为null,因为被调用的Activity必须明确设置它。 在调用onBackPressed()之前,请尝试覆盖super将结果代码设置为“已取消”。

答案 1 :(得分:0)

我认为问题可能在于您处理后退按钮的方法。这是我的后台代码:

procedure TFrmBezoekverslag.FormKeyUp(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
var
  FService: IFMXVirtualKeyboardService;
begin
  if Key = vkHardwareBack then
  begin
      TPlatformServices.Current.SupportsPlatformService
        (IFMXVirtualKeyboardService, IInterface(FService));
      if (FService <> nil) and (TVirtualKeyboardState.Visible
        in FService.VirtualKeyBoardState) then
      begin
        // Back button pressed, keyboard visible, so do nothing...
      end
      else
      begin
        // Back button pressed, keyboard not visible or not supported on this platform
        // Here you handle the code too close ZXING
        Key := 0; //If you don't want the form too close you need too add key=0
      end;
  end;
end;

如果你没有帮助,那么问题可能就在formClose方法的某个地方。

相关问题