First version
Lurker
I have an app that works great while the screen is on, but as soon as the screen is off it start slowing down until eventually in a couple of minutes is off. I notice that the mainActivity in the android studio tester stops if I turn the screen off, as soon as I turn it on the screen the main activity goes live again and the app works fine again. I have tried BATTERY_OPTIMIZATIONS, DATA_RESTRICTIONS, but it doesn't seems to work. can anybody help me on how to keep the mainActivity from stopping while the screen is off?
I have read about foreground service and tried too but I dont seem to find any service that works with web view
thanks. Attach is a pic of the main activity stooping in the android studio test environment, the green part is the app with the screen on
this is the code that I am using
public class MainActivity extends AppCompatActivity {
private WebView webView;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.wb);
WebView webview = new WebView (this);
setContentView(webview);
webview.loadUrl("http://www.apple.com");
webview.getSettings().setJavaScriptEnabled(true);
}
public void startService(View v){
String input = webView.getUrl().toString();
Intent serviceIntent = new Intent(this, RunService.class);
serviceIntent.putExtra("inputExtra", input);
startService(serviceIntent);
}
}
I have read about foreground service and tried too but I dont seem to find any service that works with web view
thanks. Attach is a pic of the main activity stooping in the android studio test environment, the green part is the app with the screen on
this is the code that I am using
public class MainActivity extends AppCompatActivity {
private WebView webView;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.wb);
WebView webview = new WebView (this);
setContentView(webview);
webview.loadUrl("http://www.apple.com");
webview.getSettings().setJavaScriptEnabled(true);
}
public void startService(View v){
String input = webView.getUrl().toString();
Intent serviceIntent = new Intent(this, RunService.class);
serviceIntent.putExtra("inputExtra", input);
startService(serviceIntent);
}
}