Good morning
Well, they'll see. I have an app with a splashscreen (in portrait orientation) that then loads an activity whose orientation is landscape and you need to block in that specific orientation while the user is browsing.
My activity landscape has a webView and a progressdialog that I want to be displayed while the webview loads the URL.
- EDIT The webView no longer enters the onReceivedError method, the error was a syntax topic in the URL. However, the ProgressDialog remains showing even though you have finished loading the page.
The problem is that when I do the change of activities. The webview always enters the onReceivedError method
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import java.util.StringTokenizer;
public class Main extends AppCompatActivity implements View.OnClickListener{
private ImageButton ibtnRefresh;
private ProgressDialog pd;
private ProgressBar progressBar;
private WebView webView;
public static String codeBar = "";
private static final boolean AUTO_HIDE = true;
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
private static final int UI_ANIMATION_DELAY = 300;
private final Handler mHideHandler = new Handler();
private View mContentView;
private final Runnable mHidePart2Runnable = new Runnable() {
@SuppressLint("InlinedApi")
@Override
public void run() {
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
};
private View mControlsView;
private final Runnable mShowPart2Runnable = new Runnable() {
@Override
public void run() {
// Delayed display of UI elements
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.show();
}
mControlsView.setVisibility(View.VISIBLE);
}
};
private boolean mVisible;
private final Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
hide();
}
};
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mVisible = true;
mControlsView = findViewById(R.id.fullscreen_content_controls);
mContentView = findViewById(R.id.fullscreen_content);
progressBar = (ProgressBar)findViewById(R.id.pBar);
setContentView(R.layout.activity_main);
ibtnRefresh = (ImageButton) findViewById(R.id.ibtnRefresh);
ibtnRefresh.setOnClickListener(this);
webView= (WebView)findViewById(R.id.fullscreen_content);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
}
});
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
view.loadUrl("blank");
view.setVisibility(View.GONE);
ibtnRefresh.setVisibility(View.VISIBLE);
pd.dismiss();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
pd = ProgressDialog.show(Main.this, "Cargando", "Espere por favor...");
}
@Override
public void onLoadResource(WebView view, String url) {
url = url.replace("%24","$");
url = url.replace("%2f","/");
url = url.replace("%40","@");
if(!url.contains("sendScanReader"))
{
}else if(!url.contains("Settings")) {
}else if(!url.contains("Search")){
}else{
view.loadUrl(Common.getURL());
}
}
@Override
public void onPageFinished(WebView view, String url) {
//Toast.makeText(getApplicationContext(),"Carga Finalizada",Toast.LENGTH_LONG).show();
if(url.contains("sendScanReader"))
{
Intent i = new Intent(getApplicationContext(),Main2Activity.class);
startActivityForResult(i,100);
}else if(url.contains("Search")){
Intent i = new Intent(getApplicationContext(),search.class);
startActivity(i);
}else if(url.contains("vta")){
Intent i = new Intent(getApplicationContext(),pagosMit.class);
startActivityForResult(i,100);
}
else{
Common.setURL(url);
}
pd.dismiss();
super.onPageFinished(view, url);
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.loadUrl(Common.getURL());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
WebView webview = (WebView) findViewById(R.id.fullscreen_content);
String newURL = Common.getURL();
webview.loadUrl(newURL);
}
}
This is the code of my Manifest.xml, in some answers I found that it was enough to add the line of configChanges but it has not worked (I have tried it with and without the keyboardHidden
<activity
android:name=".Main"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_main"
android:screenOrientation="sensorLandscape"
android:theme="@style/FullscreenTheme" />
Specifically this is what the Logcat shows me every time the application crashes
D / ViewRootImpl @ b313fdb [Main]: MSG_WINDOW_FOCUS_CHANGED 0 D / ViewRootImpl @ 1ca6187 [Loading]: dispatchDetachedFromWindow D / InputTransport: Input channel destroyed: fd = 159 D / ViewRootImpl @ b313fdb [Main]: MSG_WINDOW_FOCUS_CHANGED 1 I / InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus D / InputTransport: Input channel constructed: fd = 111 D / InputTransport: Input channel destroyed: fd = 157 E / ViewRootImpl: sendUserActionEvent () mView == null D / ViewRootImpl @ e8a1734 [SplashLoad]: dispatchDetachedFromWindow D / InputTransport: Input channel destroyed: fd = 76
In case it affects something, I tell you that the application I am doing with android Studio and my test equipment is a Samsung S7 EDGE
compileSdkVersion 26
buildToolsVersion "26.0.1"
minSdkVersion 15
targetSdkVersion 26