强迫我的活动前景?

mik*_*ike 5 android asynchronous

我有一个启动器风格的应用程序.一旦用户启动应用程序,时钟开始计时,并在一段时间后,用户返回到我的应用程序的主要活动,并通知时间已到.

为了实现这一点,我有一个AsyncTask,其doInBackground定期检查已经过了多长时间(这部分工作正常).然后:

    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Intent intent = new Intent(getApplicationContext(), HomeScreenMain.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
    }
Run Code Online (Sandbox Code Playgroud)

唯一的问题是它将我的应用程序保留在后台,虽然我假设正在启动适当的活动.所以我的问题是,当时间到期时,我不仅可以开始此活动,还可以将其置于用户可能已从我的应用中启动的任何应用程序的前台?

mik*_*ike 0

将我的原始代码替换为以下内容:

protected void onPostExecute(String s) {
    super.onPostExecute(s);
    Intent intent = new Intent();
    intent.setClass(HomeScreenMain.this, HomeScreenMain.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getApplicationContext().startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

成功了。