我需要从后台服务重新启动我的主要 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/