活动以某种方式起作用但不可见

Posted

技术标签:

【中文标题】活动以某种方式起作用但不可见【英文标题】:An activity somehow works but is not visible 【发布时间】:2021-03-26 22:23:17 【问题描述】:

我目前正在修改现有应用程序。以前一切都很完美,我不知道出了什么问题。基本上:

    启动应用时会出现启动画面 2 秒后出现登录屏幕 登录后应该有一个主屏幕,但应用程序显然已关闭

发生了什么:

    Splash.java - 2 秒后启动 MainActivity

    public class Splash extends AppCompatActivity 
    
    private final int SPLASH_DISPLAY_LENGTH = 2000;
    
    @Override
    public void onCreate(Bundle icicle) 
     super.onCreate(icicle);
     setContentView(R.layout.splash_screen);
    
     new Handler().postDelayed(new Runnable()
         @Override
         public void run() 
             Intent mainIntent = new Intent(Splash.this,MainActivity.class);
             Splash.this.startActivity(mainIntent);
             Log.e("Splash", "startActivity");
             Splash.this.finish();
             Log.e("Splash", "finish");
         
     , SPLASH_DISPLAY_LENGTH);
    
    
    

    MainActivity.java - 显然它工作正常 - 我把日志消息放在这里,Logcat 告诉我方法正在运行并且 setContentView 也在工作。

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    
     Log.e(TAG, "main activity: " + "onCreate");
    
     startTimerService();
    
     //LanguageHelper.onAttach(this);
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     //setVisible(true);
    
     Log.e(TAG, "main activity: " + "setContentView");
    
     initUI();
     Log.e(TAG, "main activity: " + "initUI");
    
     androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar);
     toolbar.bringToFront();
     Log.e(TAG, "main activity: " + "toolbar");
    
     if(firstRun)
     
         //YOUR FIRST RUN CODE HERE
         //int i  = RfidReaderSingleton.getInstance(this).RestoreFactory();
    
         //////////////////////////////////
         //checkCredentials();
         /////////////////////////////////
    
         checkForUpdates();
         checkBluetooth();
         //tcp_buttonToast.makeText(getApplicationContext(), "FIRST RUN: " + i, Toast.LENGTH_SHORT).show();
     
     firstRun = false;
    
     Log.e(TAG, "main activity: " + "firstRun" + firstRun);
    
     showPhoneStatePermission();
     Log.e(TAG, "main activity: " + "showPhoneStatePermission");
    
    
    

CheckCredentials 负责打开日志屏幕,这部分也可以工作。

@Override
protected void onResume()
    super.onResume();
    sendMessage(MSG_HIDE_WAIT, null);

    //ToDo
    checkCredentials();

    //GRID
    InitTest(this);
    Log.e("MainActivity", "InitTest");
    //GRID


private void checkCredentials()
    UserModel userModel = DBUserAdapter.getInstance(this).userOperation.getUserModel();
    if(userModel.isRemembered())
        if(!userModel.isLicenseActivated())
            Toast.makeText(getApplicationContext(),
                    getText(R.string.logging_result_401) , Toast.LENGTH_LONG).show();
            Log.e("We'startLoginActivity", "1");
            startLoginActivity();
        
        if(userModel.getToken().equals(""))
            Log.e("We'startLoginActivity", "2");
            startLoginActivity();

        
    
    else
        if(!userModel.isUserStillLogin())
            DBUserAdapter.getInstance(this).userOperation.cleanUserModel();
            Log.e("We'startLoginActivity", "3");
            startLoginActivity();
        
    
    DBUserAdapter.getInstance(this).userOperation.updateLastLogin();
    HttpUtils.SetToken(userModel.getToken());


 private void startLoginActivity()
    mStartForResult.launch(new Intent(this, PlatformLoginActivity.class));

    在 PlatformLoginActivity 中的正确日志完成后,这就是问题发生的时候。该应用程序只是关闭了,但 Logcat 中没有错误 - 没有消息。在 SplashScreen 成功后创建的 MainActivity(因为 MainActivity 负责打开 PlatformLoginActivity 并且这发生正确)。当 PlatformLoginActivity 完成时 MainActivity 不可见,应用关闭,但属于 MainActivity 的 toastmessage 在屏幕中可见。

我以前从未见过这样的行为,我不知道可能是什么问题 - 我试图记录应用程序中发生的事情,但显然它有效。

任何帮助将不胜感激,因为我不知道该怎么做。

来自 logcat 的消息:

2020-12-16 10:11:17.569 3984-3984/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2020-12-16 10:11:17.570 3984-3984/? E/Zygote: accessInfo : 1
2020-12-16 10:11:17.604 3984-3984/? E/heldrfidscanne: Unknown bits set in runtime_flags: 0x8000
2020-12-16 10:11:21.250 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/Splash: startActivity
2020-12-16 10:11:21.253 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/Splash: finish
2020-12-16 10:11:21.293 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: onCreate
2020-12-16 10:11:21.478 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: setContentView
2020-12-16 10:11:21.480 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: buttonsAction
2020-12-16 10:11:21.531 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: gridView
2020-12-16 10:11:21.531 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: initUI
2020-12-16 10:11:21.532 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: toolbar
2020-12-16 10:11:21.545 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: bluetoothconn: null
2020-12-16 10:11:21.545 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: firstRunfalse
2020-12-16 10:11:21.545 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/showPhoneStatePermiss: OK
2020-12-16 10:11:21.546 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/permissionCheck: NOT GRANTED
2020-12-16 10:11:21.569 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/requestPermission: READ_EXTERNAL_STORAGE
2020-12-16 10:11:21.593 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: showPhoneStatePermission
2020-12-16 10:11:21.663 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We'startLoginActivity: 3
2020-12-16 10:11:21.685 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: InitTest
2020-12-16 10:11:21.947 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/PlatformLoginActivity: requestPermissions
2020-12-16 10:11:33.911 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/Sign in button clicked: success
2020-12-16 10:11:34.052 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiIwN2I5MmE1My01NDEwLTRhMDYtOGM3MC0xY2UwYzllMTdkMjQiLCJyb2xlIjoiUmVndWxhciIsIm5iZiI6MTYwODEwOTg5NSwiZXhwIjoxNjE1ODg1ODk1LCJpYXQiOjE2MDgxMDk4OTV9.uxLK0qnEH3e9SjXYroBtWVKC56cHl4CmVnUlzFVgVtE
2020-12-16 10:11:34.052 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/token is NOT null: OK
2020-12-16 10:11:34.055 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/userName: issdemo
2020-12-16 10:11:34.055 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/userRole: Regular
2020-12-16 10:11:34.055 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/accountType: 0
2020-12-16 10:11:34.085 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: OK
2020-12-16 10:11:34.136 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: if condition
2020-12-16 10:11:34.136 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: MSG_SYNCHRONIZE_ANNOTATION
2020-12-16 10:11:34.141 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: finish()

未启用过滤器的 Logcat:

2020-12-16 10:11:19.341 3739-3956/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2020-12-16 10:11:19.351 4222-4492/? E/NetdEventListenerService: handleMessage:  when=-2ms what=10001 obj=com.android.server.connectivity.NetdEventListenerService$DnsResultParams@6e0c47d target=com.android.server.connectivity.NetdEventListenerService$DnsEventHandler 
2020-12-16 10:11:19.499 4222-4431/? E/WindowManager: win=Windowb3aa12c u0 com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity destroySurfaces: appStopped=true win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm.AppWindowToken.destroySurfaces:1199 com.android.server.wm.AppWindowToken.destroySurfaces:1180 com.android.server.wm.AppWindowToken.notifyAppStopped:1235 com.android.server.wm.ActivityRecord.activityStoppedLocked:2597 com.android.server.wm.ActivityTaskManagerService.activityStopped:2380 android.app.IActivityTaskManager$Stub.onTransact:2180 android.os.Binder.execTransactInternal:1056 
2020-12-16 10:11:19.530 4222-4274/? E/WindowManager: win=Windowbd74f7a u0 Splash Screen pl.is-s-rfid.isshandheldrfidscanner EXITING destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.AppWindowToken.destroySurfaces:1199 com.android.server.wm.AppWindowToken.destroySurfaces:1180 com.android.server.wm.WindowState.onExitAnimationDone:5030 com.android.server.wm.WindowStateAnimator.onAnimationFinished:287 com.android.server.wm.WindowState.onAnimationFinished:5471 com.android.server.wm.-$$Lambda$yVRF8YoeNdTa8GR1wDStVsHu8xM.run:2 com.android.server.wm.SurfaceAnimator.lambda$getFinishedCallback$0$SurfaceAnimator:100 
2020-12-16 10:11:19.741 4222-4628/? E/MdnieScenarioControlService: Exception : java.io.FileNotFoundException: /sys/class/mdnie/mdnie/scenario: open failed: ENOENT (No such file or directory) , in : null , value : null , length : 0
2020-12-16 10:11:21.250 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/Splash: startActivity
2020-12-16 10:11:21.253 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/Splash: finish
2020-12-16 10:11:21.293 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: onCreate
2020-12-16 10:11:21.478 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: setContentView
2020-12-16 10:11:21.480 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: buttonsAction
2020-12-16 10:11:21.531 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: gridView
2020-12-16 10:11:21.531 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: initUI
2020-12-16 10:11:21.532 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: toolbar
2020-12-16 10:11:21.545 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: bluetoothconn: null
2020-12-16 10:11:21.545 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: firstRunfalse
2020-12-16 10:11:21.545 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/showPhoneStatePermiss: OK
2020-12-16 10:11:21.546 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/permissionCheck: NOT GRANTED
2020-12-16 10:11:21.548 3739-3956/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2020-12-16 10:11:21.551 4222-4492/? E/NetdEventListenerService: handleMessage:  when=0 what=10001 obj=com.android.server.connectivity.NetdEventListenerService$DnsResultParams@1f35706 target=com.android.server.connectivity.NetdEventListenerService$DnsEventHandler 
2020-12-16 10:11:21.569 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/requestPermission: READ_EXTERNAL_STORAGE
2020-12-16 10:11:21.593 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: main activity: showPhoneStatePermission
2020-12-16 10:11:21.663 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We'startLoginActivity: 3
2020-12-16 10:11:21.685 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/MainActivity: InitTest
2020-12-16 10:11:21.947 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/PlatformLoginActivity: requestPermissions
2020-12-16 10:11:22.534 4222-4628/? E/MdnieScenarioControlService: Exception : java.io.FileNotFoundException: /sys/class/mdnie/mdnie/scenario: open failed: ENOENT (No such file or directory) , in : null , value : null , length : 0
2020-12-16 10:11:22.850 3785-6164/? E/BufferQueueProducer: [pl.is-s-rfid.isshandheldrfidscanner/pl.is-s-rfid.isshandheldrfidscanner.activity.Splash$_3984#0] disconnect: not connected (req=1)
2020-12-16 10:11:23.602 3785-4217/? E/BufferQueueProducer: [Toast$_3984#0] disconnect: not connected (req=1)
2020-12-16 10:11:24.675 3739-3956/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2020-12-16 10:11:24.678 4222-4492/? E/NetdEventListenerService: handleMessage:  when=0 what=10001 obj=com.android.server.connectivity.NetdEventListenerService$DnsResultParams@81a53a4 target=com.android.server.connectivity.NetdEventListenerService$DnsEventHandler 
2020-12-16 10:11:24.717 3785-3842/? E/BufferQueueProducer: [com.google.android.permissioncontroller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity$_2617#0] disconnect: not connected (req=1)
2020-12-16 10:11:24.942 4222-4628/? E/MdnieScenarioControlService: Exception : java.io.FileNotFoundException: /sys/class/mdnie/mdnie/scenario: open failed: ENOENT (No such file or directory) , in : null , value : null , length : 0
2020-12-16 10:11:25.030 4222-4274/? E/WindowManager: win=Window8108b8f u0 com.google.android.permissioncontroller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity EXITING destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.AppWindowToken.destroySurfaces:1199 com.android.server.wm.AppWindowToken.destroySurfaces:1180 com.android.server.wm.WindowState.onExitAnimationDone:5030 com.android.server.wm.WindowStateAnimator.onAnimationFinished:287 com.android.server.wm.WindowState.onAnimationFinished:5471 com.android.server.wm.-$$Lambda$yVRF8YoeNdTa8GR1wDStVsHu8xM.run:2 com.android.server.wm.SurfaceAnimator.lambda$getFinishedCallback$0$SurfaceAnimator:100 
2020-12-16 10:11:25.971 4523-4523/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2020-12-16 10:11:25.973 4523-4523/? E/Zygote: accessInfo : 1
2020-12-16 10:11:25.985 4523-4523/? E/ungpassautofil: Not starting debugger since process cannot load the jdwp agent.
2020-12-16 10:11:25.986 6667-6667/? E/SKBDC: SSTAC init()::current version is 2.11.02.U2.T1
2020-12-16 10:11:25.986 6667-6667/? E/SKBDC: SSTAC [init] mLanguageCode : 589838, tempLanguageCode : 589838, getPreloadLmLoadSuccessState() : 1
2020-12-16 10:11:26.037 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:26.114 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:26.165 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:26.986 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:27.203 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:27.379 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:27.983 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:28.302 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:28.479 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:29.094 3785-3842/? E/BufferQueueProducer: [PopupWindow:badd8b9$_6667#0] disconnect: not connected (req=1)
2020-12-16 10:11:29.138 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:29.195 6667-6667/? E/SKBD: cal Dismiss keyPreviewView is null
2020-12-16 10:11:29.316 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:29.514 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:29.715 3785-3841/? E/BufferQueueProducer: [PopupWindow:badd8b9$_6667#0] disconnect: not connected (req=1)
2020-12-16 10:11:29.767 6667-6667/? E/oid.inputmetho: Resource 01120067 is a complex map type.
2020-12-16 10:11:29.767 6667-6667/? E/SKBD: caf getSystemDimesionPixelSize: NotFoundException, name =  keyboardViewStyle
2020-12-16 10:11:29.783 6667-6667/? E/SKBDC: SSTAC init()::current version is 2.11.02.U2.T1
2020-12-16 10:11:29.783 6667-6667/? E/SKBDC: SSTAC [init] mLanguageCode : 589838, tempLanguageCode : 589838, getPreloadLmLoadSuccessState() : 1
2020-12-16 10:11:29.795 6667-6667/? E/SKBD: ctm get previous
2020-12-16 10:11:29.837 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:30.294 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:30.325 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:30.443 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:30.926 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:31.240 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:31.676 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:31.907 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:32.124 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:32.584 6667-6667/? E/DecorView: mWindow.mActivityCurrentConfig is null
2020-12-16 10:11:33.253 3785-5552/? E/BufferQueueProducer: [PopupWindow:6ef797a$_6667#0] disconnect: not connected (req=1)
2020-12-16 10:11:33.311 3785-3842/? E/BufferQueueProducer: [InputMethod$_6667#0] disconnect: not connected (req=1)
2020-12-16 10:11:33.911 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/Sign in button clicked: success
2020-12-16 10:11:33.953 3739-3956/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2020-12-16 10:11:33.956 4222-4492/? E/NetdEventListenerService: handleMessage:  when=0 what=10001 obj=com.android.server.connectivity.NetdEventListenerService$DnsResultParams@5cdb978 target=com.android.server.connectivity.NetdEventListenerService$DnsEventHandler 
2020-12-16 10:11:34.052 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiIwN2I5MmE1My01NDEwLTRhMDYtOGM3MC0xY2UwYzllMTdkMjQiLCJyb2xlIjoiUmVndWxhciIsIm5iZiI6MTYwODEwOTg5NSwiZXhwIjoxNjE1ODg1ODk1LCJpYXQiOjE2MDgxMDk4OTV9.uxLK0qnEH3e9SjXYroBtWVKC56cHl4CmVnUlzFVgVtE
2020-12-16 10:11:34.052 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/token is NOT null: OK
2020-12-16 10:11:34.055 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/userName: issdemo
2020-12-16 10:11:34.055 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/userRole: Regular
2020-12-16 10:11:34.055 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/accountType: 0
2020-12-16 10:11:34.085 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: OK
2020-12-16 10:11:34.136 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: if condition
2020-12-16 10:11:34.136 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: MSG_SYNCHRONIZE_ANNOTATION
2020-12-16 10:11:34.141 3984-3984/pl.is-s-rfid.isshandheldrfidscanner E/We're in onSignIn: finish()
2020-12-16 10:11:34.193 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:11:34.241 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:11:34.286 6500-6738/? E/PBSessionCacheImpl: sessionId[28588910426393442] not persisted.
2020-12-16 10:11:34.463 3785-3785/? E/Layer: [Surface(name=AppWindowTokenfc38cea token=Token8130cd5 ActivityRecord4b03d8c u0 pl.is-s-rfid.isshandheldrfidscanner/.activity.PlatformLoginActivity t151)/@0xb9522e4 - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_5070#0]
2020-12-16 10:11:34.463 3785-3785/? E/Layer: [Surface(name=AppWindowTokenfc38cea token=Token8130cd5 ActivityRecord4b03d8c u0 pl.is-s-rfid.isshandheldrfidscanner/.activity.PlatformLoginActivity t151)/@0xb9522e4 - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_5070#0]
2020-12-16 10:11:34.463 3785-3785/? E/Layer: [Surface(name=AppWindowTokend6f3421 token=Token80a8288 ActivityRecord2b7fe2b u0 com.sec.android.app.launcher/.activities.LauncherActivity t118)/@0x8bb7866 - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_5070#0]
2020-12-16 10:11:34.463 3785-3785/? E/Layer: [Surface(name=AppWindowTokend6f3421 token=Token80a8288 ActivityRecord2b7fe2b u0 com.sec.android.app.launcher/.activities.LauncherActivity t118)/@0x8bb7866 - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_5070#0]
2020-12-16 10:11:34.463 3785-3785/? E/Layer: [Surface(name=49d29cb com.android.systemui.ImageWallpaper)/@0x708e9c5 - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_5070#0]
2020-12-16 10:11:34.463 3785-3785/? E/Layer: [Surface(name=49d29cb com.android.systemui.ImageWallpaper)/@0x708e9c5 - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_5070#0]
2020-12-16 10:11:34.470 3785-4217/? E/BufferQueueProducer: [pl.is-s-rfid.isshandheldrfidscanner/pl.is-s-rfid.isshandheldrfidscanner.activity.PlatformLoginActivity$_3984#0] disconnect: not connected (req=1)
2020-12-16 10:11:34.556 4222-4628/? E/MdnieScenarioControlService: Exception : java.io.FileNotFoundException: /sys/class/mdnie/mdnie/scenario: open failed: ENOENT (No such file or directory) , in : null , value : null , length : 0
2020-12-16 10:11:34.692 4222-4628/? E/MdnieScenarioControlService: Exception : java.io.FileNotFoundException: /sys/class/mdnie/mdnie/scenario: open failed: ENOENT (No such file or directory) , in : null , value : null , length : 0
2020-12-16 10:11:34.948 4222-4276/? E/Watchdog: !@Sync 190 [2020-12-16 10:11:34.948] FD count : 599, wdog_way : softdog
2020-12-16 10:11:36.100 3785-5552/? E/BufferQueueProducer: [Toast$_3984#0] disconnect: not connected (req=1)
2020-12-16 10:11:44.530 3739-3956/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2020-12-16 10:11:44.589 4222-4492/? E/NetdEventListenerService: handleMessage:  when=-1ms what=10001 obj=com.android.server.connectivity.NetdEventListenerService$DnsResultParams@7bf6a0a target=com.android.server.connectivity.NetdEventListenerService$DnsEventHandler 
2020-12-16 10:11:48.146 4733-4656/? E/memtrack: Couldn't load memtrack module
2020-12-16 10:11:54.269 5728-4657/? E/memtrack: Couldn't load memtrack module
2020-12-16 10:12:04.954 4222-4276/? E/Watchdog: !@Sync 191 [2020-12-16 10:12:04.954] FD count : 598, wdog_way : softdog
2020-12-16 10:12:06.381 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:12:06.432 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:12:34.967 4222-4276/? E/Watchdog: !@Sync 192 [2020-12-16 10:12:34.966] FD count : 532, wdog_way : softdog
2020-12-16 10:13:00.010 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:13:00.058 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:13:04.980 4222-4276/? E/Watchdog: !@Sync 193 [2020-12-16 10:13:04.980] FD count : 532, wdog_way : softdog
2020-12-16 10:13:34.993 4222-4276/? E/Watchdog: !@Sync 194 [2020-12-16 10:13:34.992] FD count : 532, wdog_way : softdog
2020-12-16 10:14:00.012 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:14:00.050 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:14:05.005 4222-4276/? E/Watchdog: !@Sync 195 [2020-12-16 10:14:05.005] FD count : 532, wdog_way : softdog
2020-12-16 10:14:35.018 4222-4276/? E/Watchdog: !@Sync 196 [2020-12-16 10:14:35.018] FD count : 532, wdog_way : softdog
2020-12-16 10:15:00.010 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:15:00.048 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:15:05.030 4222-4276/? E/Watchdog: !@Sync 197 [2020-12-16 10:15:05.030] FD count : 532, wdog_way : softdog
2020-12-16 10:15:35.043 4222-4276/? E/Watchdog: !@Sync 198 [2020-12-16 10:15:35.042] FD count : 532, wdog_way : softdog
2020-12-16 10:16:00.018 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:16:00.052 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:16:05.056 4222-4276/? E/Watchdog: !@Sync 199 [2020-12-16 10:16:05.055] FD count : 532, wdog_way : softdog
2020-12-16 10:16:06.693 3739-3956/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2020-12-16 10:16:06.699 4222-4492/? E/NetdEventListenerService: handleMessage:  when=-1ms what=10001 obj=com.android.server.connectivity.NetdEventListenerService$DnsResultParams@eddcc78 target=com.android.server.connectivity.NetdEventListenerService$DnsEventHandler 
2020-12-16 10:16:35.068 4222-4276/? E/Watchdog: !@Sync 200 [2020-12-16 10:16:35.068] FD count : 526, wdog_way : softdog
2020-12-16 10:16:48.245 4733-4727/? E/memtrack: Couldn't load memtrack module
2020-12-16 10:16:54.368 5728-4728/? E/memtrack: Couldn't load memtrack module
2020-12-16 10:16:55.023 4901-5501/? E/EPDG -- SIM0 [RILRECEIVER]: Incorrect EpdgIilIpcMessage IPC Message -- not initialized
2020-12-16 10:16:55.030 4554-5292/? E/ImsAdaptorImpl: setSSACInfo : ImsAdaptorImpl.
2020-12-16 10:16:55.044 4901-5501/? E/EPDG -- SIM0 [RILRECEIVER]: Incorrect EpdgIilIpcMessage IPC Message -- not initialized
2020-12-16 10:16:55.045 4554-5292/? E/ImsAdaptorImpl: setSSACInfo : ImsAdaptorImpl.
2020-12-16 10:16:55.053 4901-5501/? E/EPDG -- SIM0 [RILRECEIVER]: RX [NET_REGIST] -- RESPONSE -- not initialized
2020-12-16 10:16:55.194 4729-4729/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2020-12-16 10:16:55.197 4729-4729/? E/Zygote: accessInfo : 1
2020-12-16 10:16:55.219 4729-4729/? E/droid.messagin: Not starting debugger since process cannot load the jdwp agent.
2020-12-16 10:16:55.221 4738-4738/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2020-12-16 10:16:55.223 4738-4738/? E/Zygote: accessInfo : 1
2020-12-16 10:16:55.245 4738-4738/? E/app.telephonyu: Not starting debugger since process cannot load the jdwp agent.
2020-12-16 10:16:55.518 4738-4816/? E/ServiceBindHelper: time out 68, com.samsung.telephony.phone.service.internalservice.ISamsungInternalService$Stub$Proxy@ebbb05c
2020-12-16 10:16:55.658 4729-4805/? E/ORC/CustomerFeatureCommon: initDocument
2020-12-16 10:16:55.737 4873-5576/? E/CapabilityDiscModule<0>: checkModuleReady: module is disabled
2020-12-16 10:16:55.750 4729-4850/? E/CS/OwnCapabilityManager<0>: queryOwnCapability, cursor null
2020-12-16 10:16:55.817 4729-4822/? E/CS/CommonDbUtils: transactionMakeFail : Not exist transaction msg
2020-12-16 10:16:55.833 4873-5575/? E/CapabilityDiscModule<0>: checkModuleReady: module is disabled
2020-12-16 10:16:55.859 4729-4850/? E/CS/OwnCapabilityManager<0>: queryOwnCapability, cursor null
2020-12-16 10:16:55.890 4873-5575/? E/CapabilityDiscModule<0>: checkModuleReady: module is disabled
2020-12-16 10:16:55.893 4729-4870/? E/CS/OwnCapabilityManager<0>: queryOwnCapability, cursor null
2020-12-16 10:17:05.081 4222-4276/? E/Watchdog: !@Sync 201 [2020-12-16 10:17:05.080] FD count : 526, wdog_way : softdog
2020-12-16 10:17:05.531 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:17:05.584 5070-5070/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-12-16 10:17:35.093 4222-4276/? E/Watchdog: !@Sync 202 [2020-12-16 10:17:35.093] FD count : 526, wdog_way : softdog

【问题讨论】:

你有日志猫的消息吗? ***.com/questions/35364373/… 如果未显示日志错误,请查看此链接 @georkost 我已经添加了我在 logcat 中得到的消息 你能完整发布你的MainActivity吗? 我已经把它贴在@akhilnair下面了 【参考方案1】:

我知道我应该在我的帖子中而不是在此处发布此问题,但不幸的是,该问题只能包含 30000 个字符,而我即将发布的代码超出了该限制

MainActivity.java:

public class MainActivity extends BluetoothActivityCompat implements ICallback 

private static MainActivity mInstance;
private static boolean firstRun = true;
public static MainActivity getInstance() 
    return mInstance;


private static final String TAG = "MainActivity";

private final int MSG_ENTER_INFO = MSG_USER_BEG + 3;
private final int MSG_ENTER_USER = MSG_USER_BEG + 4;
private final int MSG_ENTER_SCANNER = MSG_USER_BEG + 5;
private final int MSG_ENTER_INVENTORY = MSG_USER_BEG + 6;
private final int MSG_ENTER_DATABASE = MSG_USER_BEG + 7;
private final int MSG_ENTER_REPORT = MSG_USER_BEG + 8;
private final int MSG_CONNECTION_ERROR = MSG_USER_BEG + 9;
private final int MSG_SYNCHRONIZE_ANNOTATION = 301;

private ConnectBluetoothDeviceDialog connectBluetoothDeviceDialog;

//GRID
private RecyclerView locations_recyclerView;
private RecyclerView.Adapter locations_mAdapter;
private LinearLayoutManager linearLayoutManager;
private ArrayList<LocationModel> locationsList = new ArrayList<LocationModel>();
//GRID

@Override
protected void onCreate(Bundle savedInstanceState) 

    Log.e(TAG, "main activity: " + "onCreate");

    startTimerService();

    LanguageHelper.onAttach(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //setVisible(true);

    Log.e(TAG, "main activity: " + "setContentView");

    initUI();
    Log.e(TAG, "main activity: " + "initUI");

    androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.bringToFront();
    Log.e(TAG, "main activity: " + "toolbar");

    if(firstRun)
    
        //YOUR FIRST RUN CODE HERE
        //int i  = RfidReaderSingleton.getInstance(this).RestoreFactory();

        //////////////////////////////////
        //checkCredentials();
        /////////////////////////////////

        checkForUpdates();
        checkBluetooth();
        //tcp_buttonToast.makeText(getApplicationContext(), "FIRST RUN: " + i, Toast.LENGTH_SHORT).show();
    
    firstRun = false;

    Log.e(TAG, "main activity: " + "firstRun" + firstRun);

    showPhoneStatePermission();
    Log.e(TAG, "main activity: " + "showPhoneStatePermission");



private void checkBluetooth()
    try
        String bluetoothConn = DBUserAdapter.getInstance(getApplicationContext())
                .userOperation
                .getUserModel()
                .getBluetoothLastConnectedDeviceName();
        Log.e(TAG, "bluetoothconn: " + bluetoothConn);
        if(bluetoothConn!=null && !bluetoothConn.isEmpty())
            PublicData.bt4Param = bluetoothConn;
        
    
    catch(Exception ex)
        Log.e(TAG, ex.toString());
    


private void startTimerService()
    TimeCounterService mSensorService = new TimeCounterService(getApplicationContext());
    Intent mServiceIntent = new Intent(getApplicationContext(), mSensorService.getClass());
    if (!isMyServiceRunning(mSensorService.getClass())) 
        startService(mServiceIntent);
    


private boolean isMyServiceRunning(Class<?> serviceClass) 
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) 
        if (serviceClass.getName().equals(service.service.getClassName())) 
            Log.i ("isMyServiceRunning?", true+"");
            return true;
        
    
    Log.i ("isMyServiceRunning?", false+"");
    return false;


@Override
protected void onStop()
    super.onStop();
    sendMessage(MSG_HIDE_WAIT, null);
    //uhfBaseActivityBluetooth.UHF_Dispose();

@Override
protected void onPause()
    super.onPause();
    for (Fragment fragment : getSupportFragmentManager().getFragments()) 
        getSupportFragmentManager().beginTransaction().remove(fragment).commit();
    
    //sendMessage(MSG_HIDE_WAIT, null);
    //uhfBaseActivityBluetooth.UHF_Dispose();


@Override
protected void onResume()
    super.onResume();
    sendMessage(MSG_HIDE_WAIT, null);

    //ToDo
    checkCredentials();

    //GRID
    InitTest(this);
    Log.e("MainActivity", "InitTest");
    //GRID


private void checkCredentials()
    UserModel userModel = DBUserAdapter.getInstance(this).userOperation.getUserModel();
    if(userModel.isRemembered())
        if(!userModel.isLicenseActivated())
            Toast.makeText(getApplicationContext(),
                    getText(R.string.logging_result_401) , Toast.LENGTH_LONG).show();
            Log.e("We'startLoginActivity", "1");
            startLoginActivity();
        
        if(userModel.getToken().equals(""))
            Log.e("We'startLoginActivity", "2");
            startLoginActivity();

        
    
    else
        if(!userModel.isUserStillLogin())
            DBUserAdapter.getInstance(this).userOperation.cleanUserModel();
            Log.e("We'startLoginActivity", "3");
            startLoginActivity();
        
    
    DBUserAdapter.getInstance(this).userOperation.updateLastLogin();
    HttpUtils.SetToken(userModel.getToken());


private void checkForUpdates()
    try
        AppUpdater appUpdater = new AppUpdater(this)
                .setDisplay(Display.DIALOG)
                .setUpdateFrom(UpdateFrom.JSON)
                .setUpdateJSON(getString(R.string.update_info_address))
                .setTitleOnUpdateAvailable(R.string.updateTitle)
                .setButtonUpdate(R.string.updateButtonOk)
                .setButtonDismiss(R.string.updateButtonCancel)
                .setContentOnUpdateAvailable(R.string.updateInformation)
                .setButtonDoNotShowAgain(null);
        appUpdater.start();
    
    catch(Exception ex)
        Log.e(TAG, ex.toString());
    


@Override
public boolean onKeyDown(int keyCode, KeyEvent event)

    if ((keyCode == KeyEvent.KEYCODE_BACK))
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //startActivity(intent);
        finish();
        System.exit(0);
        Log.e("onKeyDown", "MainActivity");
    
    return super.onKeyDown(keyCode, event);


private void initUI()
    buttonsAction();
    Log.e("MainActivity", "buttonsAction");

    //GRID
    locations_recyclerView = (RecyclerView) findViewById(R.id.foundDevices_recyclerView);
    locations_recyclerView.setHasFixedSize(false);

    // use a linear layout manager
    linearLayoutManager = new LinearLayoutManager(this);
    locations_recyclerView.setLayoutManager(new GridLayoutManager(this,3));

    // specify an adapter (see also next example)
    locationsList = DBAdapter.getInstance(getApplicationContext()).getLocationList();
    locations_mAdapter = new LocationAdapter(locationsList, MainActivity.this);

    locations_recyclerView.setAdapter(locations_mAdapter);
    Log.e("MainActivity", "gridView");

//        locations_recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() 
//            @Override
//            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) 
//                int position = parent.getChildAdapterPosition(view); // item position
//                int spanCount = 3;
//                int spacing = 10;//spacing between views in grid
//
//                if (position >= 0) 
//                    int column = position % spanCount; // item column
//
//                    outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
//                    outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)
//
//                    if (position < spanCount)  // top edge
//                        outRect.top = spacing;
//                    
//                    outRect.bottom = spacing; // item bottom
//                 else 
//                    outRect.left = 0;
//                    outRect.right = 0;
//                    outRect.top = 0;
//                    outRect.bottom = 0;
//                
//            
//        );

    //DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(locations_recyclerView.getContext(),
    //        linearLayoutManager.getOrientation());
    //locations_recyclerView.addItemDecoration(dividerItemDecoration);
    //GRID


public void refreshListView()
    locationsList.clear();
    locationsList = DBAdapter.getInstance(getApplicationContext()).getLocationList();
    locations_mAdapter.notifyDataSetChanged();
    showToast(getString(R.string.synchronization_completed));


void showToast(String message)
    Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.BOTTOM , 0,50);

    toast.show();


@Override
protected void msgProcess(Message msg) 
    Intent intent;
    switch (msg.what) 
        case MSG_ENTER_INFO:
            intent = new Intent(MainActivity.this, UserDetailActivity.class);
            startActivityForResult(intent, 0);
            break;
        case MSG_ENTER_USER:
            intent = new Intent(MainActivity.this, InfoActivity.class);
            startActivityForResult(intent, 0);
            break;
        case MSG_ENTER_DATABASE:
            intent = new Intent(MainActivity.this, DatabaseActivity.class);
            startActivityForResult(intent, 0);
            break;
        case MSG_ENTER_INVENTORY:
            intent = new Intent(MainActivity.this, LocationListViewActivity.class);
            startActivityForResult(intent, 0);
            break;
        case MSG_ENTER_SCANNER:
            intent = new Intent(MainActivity.this, TagReadingActivity.class);
            startActivityForResult(intent, 0);
            break;
        case MSG_ENTER_REPORT:
            intent = new Intent(MainActivity.this, ReportActivity.class);
            startActivityForResult(intent, 0);
            break;
        case MSG_SYNCHRONIZE_ANNOTATION:
            Log.e("In msgProcess MainA", "case MSG_SYNCHRONIZE_ANNOTATION");
            intent = new Intent(MainActivity.this, ReportActivity.class);
            startActivityForResult(intent, 0);
            break;
        default:
            break;
    
    super.msgProcess(msg);


private void buttonsAction() 
    Button info = (Button) findViewById(R.id.info_button);
    Button inw = (Button) findViewById(R.id.inw_button);
    Button database = (Button) findViewById(R.id.database_button);
    Button scan = (Button) findViewById(R.id.scan_button);
    Button report = (Button) findViewById(R.id.report_button);
    ImageButton settings = (ImageButton) findViewById(R.id.settings_button);
    ImageButton bluetooth = (ImageButton) findViewById(R.id.bluetooth_button);

    // MY NEW BUTTONS
    ImageButton bluetoothToolbar = (ImageButton) findViewById(R.id.toolbar_bluetooth_button);
    ImageButton synchronizationToolbar = (ImageButton) findViewById(R.id.toolbar_synchronization_button);
    ImageButton userToolbar = (ImageButton) findViewById(R.id.toolbar_user_button);
    ImageButton infoToolbar = (ImageButton) findViewById(R.id.toolbar_info_button);

    infoToolbar.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 
            new Thread() 
                @Override
                public void run() 
                    if (isFastClick()) 
                        return;
                    
                    sendMessage(MSG_SHOW_WAIT, getString(R.string.str_loading));
                    sendMessage(MSG_ENTER_USER, null);
                ;
            .start();
        
    );

    database.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 
            new Thread() 
                @Override
                public void run() 
                    if (isFastClick()) 
                        return;
                    
                    sendMessage(MSG_SHOW_WAIT, getString(R.string.str_loading));
                    sendMessage(MSG_ENTER_DATABASE, null);
                ;
            .start();
        
    );

    inw.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 
            new Thread() 
                @Override
                public void run() 
                    if (isFastClick()) 
                        return;
                    
                    sendMessage(MSG_SHOW_WAIT, getString(R.string.str_loading));
                    sendMessage(MSG_ENTER_INVENTORY, null);
                ;
            .start();
        
    );

    scan.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 
            new Thread() 
                @Override
                public void run() 
                    if (isFastClick()) 
                        return;
                    
                    sendMessage(MSG_SHOW_WAIT, getString(R.string.str_loading));
                    sendMessage(MSG_ENTER_SCANNER, null);
                ;
            .start();
        
    );

    report.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 
            new Thread() 
                @Override
                public void run() 
                    if (isFastClick()) 
                        return;
                    
                    sendMessage(MSG_SHOW_WAIT, getString(R.string.str_loading));
                    sendMessage(MSG_ENTER_REPORT, null);
                ;
            .start();
        
    );

//        settings.setOnClickListener(new View.OnClickListener() 
//            @Override
//            public void onClick(View v) 
//                new Thread() 
//                    @Override
//                    public void run() 
//                        if (isFastClick()) 
//                            return;
//                        
//                        sendMessage(MSG_SHOW_WAIT, getString(R.string.str_loading));
//                        sendMessage(MSG_ENTER_INFO, null);
//                    ;
//                .start();
//
//            
//        );




    ICallback callback = this;

    bluetoothToolbar.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 

            FragmentManager fm;
            fm = getSupportFragmentManager();
            ConnectBluetoothDeviceDialog connectBluetoothDeviceDialog =
                    ConnectBluetoothDeviceDialog.newInstance(callback);
            connectBluetoothDeviceDialog.showDialog(fm);

        
    );

    synchronizationToolbar.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 

            FragmentManager fm;
            fm = getSupportFragmentManager();
            SynchronizationMainDialog synchronizationMainDialog =
                    SynchronizationMainDialog.newInstance(callback);
            synchronizationMainDialog.showDialog(fm);

        
    );


    userToolbar.setOnClickListener(new View.OnClickListener() 
        @Override
        public void onClick(View v) 
            Log.e("userToolbar button", "pressed");


            FragmentManager fm;
            fm = getSupportFragmentManager();
            UserDialog userDialog =
                    UserDialog.newInstance(callback);
            userDialog.showDialog(fm);

        
    );




private void startLoginActivity()
    mStartForResult.launch(new Intent(this, PlatformLoginActivity.class));


ActivityResultLauncher<Intent> mStartForResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
        new ActivityResultCallback<ActivityResult>() 
            @Override
            public void onActivityResult(ActivityResult result) 
                if (result.getResultCode() == MSG_SYNCHRONIZE_ANNOTATION) 
                    FragmentManager fm;
                    fm = getSupportFragmentManager();
                    SynchronizationAnnotationDialog synchronizationAnnotationDialog =
                            SynchronizationAnnotationDialog.newInstance();
                    synchronizationAnnotationDialog.showDialog(fm);

                    Log.e("ActivityResultLauncher", "MSG_SYNCHRONIZE_ANNOTATION");
                    // Handle the Intent
                
            
);

// Checking if user has changed language using the 'InfoActivity'. If yes -cann we need to
// restart the activity to update the language.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)

    super.onActivityResult(requestCode, resultCode, data);
    Log.e(TAG, "requestCode: " + requestCode);
    if(requestCode==0)
    
        try 
            if(data.getBooleanExtra("languageChanged", false))
                restartActivity();
            
        
        catch(Exception ex)
            Log.e(TAG, ex.toString());
        
    
    if(resultCode == MSG_CONNECTION_ERROR)
        FragmentManager fm;
        fm = getSupportFragmentManager();
        BluetoothConnectionErrorDialog bluetoothConnectionErrorDialog =
                BluetoothConnectionErrorDialog.newInstance();
        bluetoothConnectionErrorDialog.showDialog(fm);
    


private void restartActivity() 
    Intent intent = getIntent();
    finish();
    startActivity(intent);



//We are calling this method to check the permission status
private boolean isReadStorageAllowed() 
    //Getting the permission status
    int result = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);

    //If permission is granted returning true
    if (result == PackageManager.PERMISSION_GRANTED)
        return true;

    //If permission is not granted returning false
    return false;


private final int STORAGE_PERMISSION_CODE = 23;

private void showPhoneStatePermission() 

    Log.e("showPhoneStatePermiss", "OK");

    int permissionCheck = ContextCompat.checkSelfPermission(
            this, Manifest.permission.READ_EXTERNAL_STORAGE);

    if (permissionCheck != PackageManager.PERMISSION_GRANTED) 
        Log.e("permissionCheck", "NOT GRANTED");

        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) 
            Log.e("READ_EXTERNAL_STORAGE", "the app has requested the permission previously and the user denied the requst");

            showExplanation("Permission Needed", "Rationale", Manifest.permission.READ_EXTERNAL_STORAGE, STORAGE_PERMISSION_CODE);

         else 
            requestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, STORAGE_PERMISSION_CODE);
            Log.e("requestPermission", "READ_EXTERNAL_STORAGE");
        
     else 
       // Toast.makeText(MainActivity.this, "Permission (already) Granted!", Toast.LENGTH_SHORT).show();
    

    permissionCheck = ContextCompat.checkSelfPermission(
            this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) 
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) 
            showExplanation("Permission Needed", "Rationale", Manifest.permission.WRITE_EXTERNAL_STORAGE, STORAGE_PERMISSION_CODE);
         else 
            requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, STORAGE_PERMISSION_CODE);
        
     else 
       // Toast.makeText(MainActivity.this, "Permission (already) Granted!", Toast.LENGTH_SHORT).show();
    


@Override
public void onRequestPermissionsResult(
        int requestCode,
        String permissions[],
        int[] grantResults) 
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) 
        case STORAGE_PERMISSION_CODE:
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) 
                //Toast.makeText(MainActivity.this, "Permission Granted!", Toast.LENGTH_SHORT).show();
             else 
                Toast.makeText(MainActivity.this, "Permission Denied!", Toast.LENGTH_SHORT).show();
            
    


private void showExplanation(String title,
                             String message,
                             final String permission,
                             final int permissionRequestCode) 
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(title)
            .setMessage(message)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() 
                public void onClick(DialogInterface dialog, int id) 
                    requestPermission(permission, permissionRequestCode);
                
            );
    builder.create().show();


private void requestPermission(String permissionName, int permissionRequestCode) 
    ActivityCompat.requestPermissions(this,
            new String[]permissionName, permissionRequestCode);


@Override
public void showLoading() 
    sendMessage(MSG_SHOW_WAIT, getString(R.string.str_loading));


@Override
public void hideLoading() 
    sendMessage(MSG_HIDE_WAIT, null);

【讨论】:

以上是关于活动以某种方式起作用但不可见的主要内容,如果未能解决你的问题,请参考以下文章

可疑的演员阵容中没有继承自的解决方案中的类型->为啥/以某种方式起作用

ExtJs:在非活动选项卡中以编程方式选择 GridPanel 的行不起作用?

当我调用可见性时,Android 动画不起作用

以编程方式调用 UIRefreshControl 不起作用

以编程方式制作的约束不起作用

链表创建一个新指针以添加值但不起作用