how to hide the app content when it is viewed on overview mode?
i have tried to use the onPause() method to call an alert so that it will cover the screen like the code below, but the alert only show after i go back to the app, it does not show the alert while it is on overview
#Override
protected void onPause() {
super.onPause();
openSearch();
}
i expected the onPause() method to cover the app while it is on overview but it is only called after i resume to the app
Add the following in onCreate of activity. This also blocks the user from taking screenshots of the activity.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
Related
I'm new to Android, working on a webview app. I have created a custom HTML error page in asset folder for loading when internet not available, it is working fine.
My issue is when internet is back, after browsing different screen on back button press it shows the error page also, how to skip this.
#Override
public void onBackPressed() {
if (myWebView.canGoBack()) {
myWebView.goBack();
} else {
DashActivity.super.onBackPressed();
}
}
In the no internet activity, when you open another activity on getting the internet connection back, you are forgetting to finish() the activity. Due to that, the activity opens again.
There can be error because you didn't finish the activity so.
You should just write finish() instead of DashActivity.super.onBackPressed()
If I launch the app from the home screen (by taping the app icon), then I navigate through the app and then I leave the app, when I reopen the app the same way (by taping the app icon from the home screen) it will resume the previous state and show the last activity I was on before leaving the app.
That part works as expected.
Here is the issue:
If I first launch the app from the play store or manually from the apk installer, and then reopen the app another way (by taping the app icon from the home screen for instance), the app will start a new instance of the main activity and will add it the previous navigation stack (If I press the back button it will go back to the last activity I was on before leaving the app).
I always want the app to open the last activity from background, no matter how the app was first launched (via the home screen or the play store or manually).
I already tried stuff like that in the main activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isTaskRoot()
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
[...]
}
but the finish() call crashes the app.
I actually found why finish() crashed the app: onDestroy() was called and it tried to unregister a receiver that was not registered yet, so the app crashed: Unable to destroy activity [...] Receiver not registered.
So that code actually works fine for my issue:
if (!isTaskRoot()
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
I just didn't pay attention to onDestroy()
I have a webview application, and I need to refresh(using webview.Reload()) the webview whenever the app has been running in the background (has not been killed) and is brought back.How would I do that?
As a user navigates through, out of, and back to your app, the Activity instances in your app transition through different states in their lifecycle. The Activity class provides a number of callbacks that allow the activity to know that a state has changed: that the system is creating, stopping, or resuming an activity, or destroying the process in which the activity resides.
#Override
public void onResume() {
super.onResume();
webView.reload();
}
https://developer.android.com/guide/components/activities/activity-lifecycle
I am using Mobage Gaming API. And I want to resume to my Mobage Login screen.
I am using following code:
#Override
public void onResume() {
super.onResume();
if (Mobage.isInitialized()) {
Mobage.getInstance().onResume();
Log.d("MobageResume", "MobageResume onResume()");
}
}
Mobage.getInstance().onResume(); method is fired but nothing happens in the device. It is not display Mobage Login screen again.
The issue is resolved now. It is due to AndroidManifest.xml in activity Android: launchMode=SingleTask. By removing this the Mobage Login screen is properly displayed.
For detail Please see following link:
Android: launchMode=SingleTask problem
I have a Flash video playing in a WebView. When the user hits the home button, I want to stop the video. I attempt to do this in my Activity:
#Override
protected void onStop() {
Log.i(tag, "onStop");
super.onStop();
this.webView.onPause();
}
I see "onStop" logged out whenever I hit the home button, but the video only stops the first time. I can still hear the audio on all the other times.
The following hack stops the video all the time, but (A) it only stops Flash and not any Javascript timers and (B) it can't shut down any generic Flash video - it can only shut down objects with ID "flashVideo" and with a hook named "stopVideo".
#Override
protected void onStop() {
Log.i(tag, "onStop");
super.onStop();
this.webView.loadUrl("javascript:$('flashVideo').stopVideo();");
}
You could try calling this.webView.destroy() in the onStop() but you would need to reinstantiate the webview and re-add the WebView to the activity programmatically since webView.destroy basically makes it so no other methods may be called on a WebView after destroy.
I had the same issue and i made it work by retaining the state in the BackPressed Method
add the follwing code
mVideoView.stopPlayback();
mCustomViewCallback.onCustomViewHidden();
this might help