How can I show android splash screen when the application goes to the back ground?
The issue is that I need to hide my application main page when the user sends the app to the background, and when s/he double tabs the home button, they will see the splash screen.
We were using the following inside our code :
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
getWindow().setFlags(LayoutParams.FLAG_SECURE,
LayoutParams.FLAG_SECURE);
.
.
It looks like it is fixing the issue, but this code is preventing the user from taking screenshot on the device if the app is in the foreground.
I'm not sure how to implement what i need like I did in iOS.
thanks.
Now I haven't personally tried this so I'm not sure if it'll work, but you can try overriding the onPause() method. After overriding onPause() add code that sets your splash screen to cover the entire activity. This should put the image as the app preview in the Recents Panel. Then override the onResume() method to remove the image from the activity, giving the user control again.
Related
I would like to be able to hide the content of the app when it is not in foreground, for example, when I click the overview button(task list), the Chase banking app would just show pure solid color and hide all the content. Does anyone know how to do this?
I found out the answer should be add the following in onCreate of activity. This also block user from taking screen shots of the activity.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
You can override onStop method in an activity and make the view invisible.
My question is about the Android system taking snapshot of application screen when entering background. I have some secure content in application which I would like to hide in that point, so if user enters background and opens recent apps, I could show always the same content (for example splash screen) for my application instead of the last screen visible before entered to background.
Is this possible at all?
Thanks.
Please do not post answers about FLAG_SECURE, I do not want the screen to be black and also found a bug from it: http://code.google.com/p/android/issues/detail?id=64086
Use FLAG_SECURE .
Usage:
public class FlagSecureTestActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(LayoutParams.FLAG_SECURE,
LayoutParams.FLAG_SECURE);
setContentView(R.layout.main);
}
}
That will prevent from a screenshot being taken of that activity. And will show a blank screen for that app in the recent apps list.
Edit:
Other than FLAG_SECURE there doesn't seem any method to prevent a screenshot from being taken. However, I'd suggest this unclean workaround instead. I've not tried this, just an idea:
Override the onPause() and onBackPressed() methods of the Activity. So when the home or back button are pressed, these are called.
Then , inside these, use setContentView() to show another dummy view or a splash screen for that matter. So that this splash view becomes the last shown View.
After point 2, call super.onPause() or super.onBackPressed() , so that the screenshot is taken, of this splash screen. Don't call them before point 2.
How can i change the screen of an activity when pressing any button on an android phone that takes one away from the running app.
I'm trying to get a blank screen to show up on the "recents" screen, instead of a snapshot of the app.
You can use this option and check if it helps you meet your need.
android:excludeFromRecents="true"
Add this to your activities in the application manifest if you do not want the app to be shown in the recent apps list. One drawback is that you would not be able to resume the app from the Recents list. Not sure if this is what you need.
The other way is to have a 'Blank Activity', which you start when your actual activity pauses. You can then finish the 'Blank Activity' on its Resume. This way, you will have your app shown on the Recents list, but with a blank screen.
You can call finish() for activity but that will kill activity. I think that will leave blank screen. Or destroy(). Try both respond with results.
you might want to change the onpause() or onclose() functions of your app. they are the last thing android execute before leaving,therefor you can change the aspect off your app just before you leave it
EDIT :
Maybe if you create PopupWindow and set it to full screen, and color black when exiting no preview would be shown, but app would still be running (idea of user DjDexter5GH) in the onpause() and onclose() functions. therefgor,when you leave,a black(or whatever you want) screen is pushed in front
you can then close it in the onrestart(is it called this?)
I am using an implementation of locker screen which locks (is displayed on top) the current activity when it is idle for X seconds.
However the view for the locker activity is not displayed in the preview image after clicking the Home and Recent buttons.
How could I force to make my app's view blank or display my locker view in the recent list?
I could set my activity visible to gone, but is there any other solution?
Try FLAG_SECURE:
public class FlagSecureTestActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.main);
}
}
It will automatically display a grey background when Recents button is pressed.
A possible side-effect would be that you cant take the screenshot of the activity you are defining this way.
Try the attribute, android:noHistory="true" for the activity tag in the manifest file.
The recents app gets something like a "screenshot" when the app goes to background, so before go to background you can fill your activity with a black LinearLayout and onResume check if this LinearLayout is showing and hide. Maybe there are better solutions but this may works.
I've made an Android app, and in its first view you can select a date from a calendar. Everything works fine, but if i push the arrow button on my phone the app seems to close, and i get back to the home screen of my phone.
However if I restart the app by clicking its icon i can see the splash screen, and after this the first view... where the date i selected b4 closing the app is still selected!
Is there a way to completely clear all the variable of my app?
Thanks
Look at the activity livecycle: http://developer.android.com/reference/android/app/Activity.html
At onResume() you could clear the variables!
Your activity isn't destroyed right away when you hit the back button. If you want all data to be destroyed when someone leaves the app then clear the data out in the onPause() method.