moveTaskToBack后恢复Android Jelly Bean(true)

时间:2016-09-20 18:37:36

标签: java android android-activity android-4.1-jelly-bean

我对android Jelly Bean有一些问题。 我想在后台活动中加载webview,当webivew网站完成加载时,我想显示活动 对于后台发送活动,我使用Activity.moveTaskToBack(true);,并使用startActivity恢复Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP。它在所有版本上都很完美,期待Jelly Bean :(。在Jelly Bean Activity.onResume上执行但活动没有显示。

示例代码:

public class TestActivity extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WebView webView = new WebView(this);
        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://google.com");

        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.addView(webView);
        setContentView(layout, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        moveTaskToBack(true);

        Toast.makeText(this, "SEND ACTIVITY TO BACK", Toast.LENGTH_SHORT).show();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(TestActivity.this, "TRY RESUME ACTIVITY", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(TestActivity.this, TestActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        }, 10000);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        Toast.makeText(this, "ON NEW INTENT", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();

        Toast.makeText(this, "ON RESUME", Toast.LENGTH_SHORT).show();
    }

}

0 个答案:

没有答案