gpt4 book ai didi

android - 从服务恢复 android Activity

转载 作者:太空狗 更新时间:2023-10-29 15:53:48 25 4
gpt4 key购买 nike

我需要从后台服务重新启动我的主要 Activity 。
我通过 BroadcastReceiver 获得我的服务结果,我需要恢复它(在一些操作之后)。

这可能吗?
我该怎么做?

我试过这个解决方案 Resume application and stack from notification但它对我不起作用。

编辑:
那是我的接收器:

private BroadcastReceiver receiver = new BroadcastReceiver() {


@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
int resultCode = bundle.getInt(DownloadService.RESULT);
if (resultCode == RESULT_OK) {
Log.i("MyApp", "RESULT OK");
final Intent mainIntent = new Intent(context, MainActivity.class);
mainIntent.setAction(Intent.ACTION_MAIN);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(mainIntent);
} else {
Toast.makeText(MainActivity.this, "KO",Toast.LENGTH_LONG).show();
}
}
}

};

最佳答案

Intent intent = new Intent(context.getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
context.getApplicationContext().startActivity(intent);

关于android - 从服务恢复 android Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19670548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com