Reputation: 127
i have some problem with android Jelly Bean.
I want to load webview in background activity, and when webivew site is complete loaded, i want to show activity.
For send activity in background i use Activity.moveTaskToBack(true);
, and to resume it startActivity
with Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
. It's worked perfect on all versions expect Jelly Bean :(. On Jelly Bean Activity.onResume executed but activity not showed.
Example code:
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();
}
}
Upvotes: 2
Views: 252