我需要从后台服务重新启动我的主要活动。
我通过BroadcastReceiver得到我的服务结果,我需要恢复它(在一些操作之后)。从服务中恢复Android活动
可能吗?
我该怎么做?
我试过这个解决方案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();
}
}
}
};
你是什么意思,它不适合你?你有例外吗?你是否需要应用程序进入前台并完全中断用户的行为? –
没有错误。该应用程序没有恢复,我敢肯定服务正在运行,因为我有一些日志。 – enfix
发布一些代码,以便我们可以看到你在做什么。大量的应用程序从包括我自己在内的通知中启动。这绝对有效,并可能在Android上。 –