从后台启动活动,不在onResume()中运行该功能

发布于 2025-01-21 12:42:14 字数 1017 浏览 0 评论 0原文

在我的应用程序中,当应用程序停止录制音频时,它会启动另一项活动并在onResume()中运行函数自动系统(),但是当设备锁定时,它不会从后台运行该函数,是否可以运行一个方法启动时从背景中的第二个活动中的功能。

录制活动启动另一个活动

if (autoSyncSwitchSelected1) { // If user's preference is automatic syncing then set the 
                               // activity to syncRecording which will call the 
                               // automaticSync() method
                                    
   handleSelectedFiles("syncRecordings", 3); // Start activity RecordingsExplorer for result
                            
}

录制资源管理器

@Override
protected void onResume() {
    super.onResume();
    System.out.println("onResume");
    // get default shared preferences file:
    settings = PreferenceManager.getDefaultSharedPreferences(this); 
    autoSyncSwitchSelected = settings.getBoolean(Config.PREF_AUTO_SYNC, true);
    if(autoSyncSwitchSelected) {
        automaticSync();
    }
}

In my application, when the app stops recording audio it launches another activity and runs the function automaticSync() in the onResume(), but when the device is locked it does not run the function from the background, is there a way to run a function in the second activity from the background when launched.

Recording Activity launching another activity

if (autoSyncSwitchSelected1) { // If user's preference is automatic syncing then set the 
                               // activity to syncRecording which will call the 
                               // automaticSync() method
                                    
   handleSelectedFiles("syncRecordings", 3); // Start activity RecordingsExplorer for result
                            
}

Recording Explorer

@Override
protected void onResume() {
    super.onResume();
    System.out.println("onResume");
    // get default shared preferences file:
    settings = PreferenceManager.getDefaultSharedPreferences(this); 
    autoSyncSwitchSelected = settings.getBoolean(Config.PREF_AUTO_SYNC, true);
    if(autoSyncSwitchSelected) {
        automaticSync();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦行僧 2025-01-28 12:42:14

onResume 是该应用程序与用户交互的状态。当应用在前景时,这就是称为。正如您所说的“当设备被锁定时,它不会从后台运行该功能” ,是的,这是正确的。 onResume 只有当应用程序在前景中才会在procgroum 。当您的活动不再可见对用户或背景中时,它已输入 onstop 状态。看看 activity-activity-contivation-lifecycle-concept

OnResume is the state in which the app interacts with the user. It's called when the app is in the foreground. As you said "when the device is locked it does not run the function from the background", yes this is correct. OnResume will only be called when the app is in the foreground. When your activity is no longer visible to the user or in the background, it has entered the OnStop State. Have a look on Activity-lifeCycle-Concept.

成熟稳重的好男人 2025-01-28 12:42:14

onResume()仅在手机不处于锁定状态时起作用。
您可以尝试其他方法,例如背景服务,广播接收器,也可以使用Onstop方法覆盖

the OnResume() only works when the phone is not in locked state.
You can try other methods like Background Service, Broadcast Receiver or you can override using onStop method

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文