[英]Put onReceive on wait until the started activity finishes
In the onReceive(), I want to create a new Intent and start a new Activity. 在onReceive()中,我想创建一个新的Intent并启动一个新的Activity。 After the activity finishes, I want to get back to the same line from where I left for the activity.
活动结束后,我想回到离开活动所在的同一行。 I know that I cannot use BroadcastReceiver class for achieving this.
我知道我不能使用BroadcastReceiver类来实现此目的。 How can this be achieved?
如何做到这一点? Below is the onReceive() code:
下面是onReceive()代码:
final BroadcastReceiver mPairingRequestRecevier = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(intent.getAction()))
{
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR);
if (type == BluetoothDevice.PAIRING_VARIANT_PIN)
{
abortBroadcast();
String passkey="hey";
Intent passkeyIntent = new Intent(context.getApplicationContext(),TestActivity.class);
passkeyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
passkeyIntent.putExtra("passkey",passkey);
context.startActivity(passkeyIntent);
Log.d("after returning...",passkey);
}
else
{
Log.d("Unexpected pairingtype:" , type+"");
}
}
}
};
Any idea that can achieve this would be appreciated. 任何可以实现这一目标的想法将不胜感激。
您可以使用startActivityFor result而不是startActivity来启动活动。使其执行一些任务,然后将结果返回到先前的活动。看一下: 如何在Android上管理`startActivityForResult`?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.