从DeviceAdminReceiver传递结果返回到调用活动 [英] Pass result from DeviceAdminReceiver back to calling activity

查看:327
本文介绍了从DeviceAdminReceiver传递结果返回到调用活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活动(MyActivity.class)执行设置屏幕锁定的方法如下:

My activity (MyActivity.class) executes the method to set the screen lock as follow:

startActivityForResult(Security.setLockscreen(getBaseContext()), 1001);

然后我的接收器类记录的更改锁屏如下:

Then my receiver class logs the change to the screen lock as follow:

public class MyDeviceAdminReceiver extends DeviceAdminReceiver {
   @Override
   public void onPasswordChanged(Context context, Intent intent) {
        super.onPasswordChanged(context, intent);
        // pass result back to calling activity
        intent = new Intent(context, MyActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("pwdChange", true);
        context.startActivity(intent);
    }
}

然后我处理结果从 onActivityResult 方法 MyActivity 类。

就是上面的最好方式传递结果返回到活动?我注意到上面创建重用MyActivity类的现有实例的MyActivity类的另一个实例吧。

Is the above the best way to pass result back to the activity? I noticed the above creates another instance of MyActivity class instead of reusing an existing instance of MyActivity class.

有没有将数据传递回调用活动的另一种更有效的方式?

Is there another more efficient way of passing data back to the calling activity?

推荐答案

我已经找到一种解决方案是使用共享preferences 从传递数据 DeviceAdminReceiver 类的<​​code>活动类。

One solution I've found is to use SharedPreferences to pass data from a DeviceAdminReceiver class to an Activity class.

我敢肯定有其他工作的解决方案,其他有经验的开发人员可以在这个主题发表和大家一起分享。

I'm sure there are other working solutions that other experienced developers can post in this thread to share with everyone.

这篇关于从DeviceAdminReceiver传递结果返回到调用活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆