vendredi 6 mars 2015

Android app stop activity contain a webview when press (android) home button


Vote count:

0




Testing device : Xperia M2 (Android 4.4.4)


The Story :


I have a music service started on main activity. The user launch a new Activity with WebView (music still playing). When the user go back to the home screen of Android, this message appear in logcat :


W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection


After ~30sec the app & service stop. (with no error and nothing else in logcat).


The source of my WebView Activity :



public class WebActivity extends FragmentActivity {
private ProgressBar pb;
private WebView webview;

private Integer type;

@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.webpage);

String url = "";
String activity_name = "";

pb = (ProgressBar) findViewById(R.id.webLoad);
pb.getProgressDrawable().setColorFilter(Color.GRAY, Mode.SRC_IN);
pb.setMax(100);

webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setSupportZoom(true);
webview.setWebViewClient(new WebViewClient() {

public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
webview.setWebChromeClient(new MyWebViewClient());
WebActivity.this.pb.setProgress(0);


Bundle extras = getIntent().getExtras();
if (extras != null) {
activity_name = extras.getString("ACTIVITY_NAME");
url = extras.getString("LOAD_URL");
type = extras.getInt("TYPE");
webview.loadUrl(url);
}
}

private class MyWebViewClient extends WebChromeClient {
@Override
public void onProgressChanged(WebView view, int newProgress) {
WebActivity.this.setValue(newProgress);
if (newProgress == 100)
pb.setVisibility(View.INVISIBLE);
super.onProgressChanged(view, newProgress);
}
}

public void setValue(int progress) {
this.pb.setProgress(progress);
}

@Override
public void onBackPressed() {
if (type == 1) {
Intent intent;
intent = new Intent(this, PlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
this.finish();
//super.onBackPressed();
} else {
finish();
}
}
}


asked 2 mins ago







Android app stop activity contain a webview when press (android) home button

Aucun commentaire:

Enregistrer un commentaire