orientation-changes

Saving some data on orientation change in Android

此生再无相见时 提交于 2019-12-03 20:57:46
问题 As far as I've understood, your Android activity will be recreated for the new orientation on any orientation changes. Is there a way to store / save some of the data from the original orientation upon the orientation change? I'd like to store some Bitmaps, so I don't have to load it again on the orientation change. 回答1: Using static variables/classes is a bad approach in terms of maintainability and debugging. I have been using Activity.onRetainNonConfigurationInstance but I found out just

App size is too big because of too many images

落爺英雄遲暮 提交于 2019-12-03 17:00:03
I'm creating an universal app. For one screen, I'm displaying 6 images (png format) in a grid using this control. Also this screen supports both portrait and landscape orientation. I've created a set of images in different resolutions for all the iDevices and named them using the correct naming convention as follows. name~iphone.png name@2x~iphone.png name~ipad.png name@2x~ipad.png name-568h@2x~iphone.png (iPhone 5) And I had to create another set of these images since I support both orientation and I can't use the same images as above because in landscape it would stretch. Now I have close to

Fragment's onActivityResult not called after orientation change

一笑奈何 提交于 2019-12-03 06:12:22
Please note, this question is not a duplicate of the following: https://stackoverflow.com/questions/19006776/onactivityresult-not-working-with-fragments onActivityResult not working on fragments Also, another similar question was asked before, but that doesn't mention orientation changes (and is unresolved). My onActivityResult method in the Fragment does get called if I don't switch orientation. However, if I follow these steps, it doesn't get called: Load fragment in FragmentActivity. From the fragment: startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), Constants.REQ_CODE

Duplicate permission request after orientation change

折月煮酒 提交于 2019-12-03 05:46:33
Because the Android SDK 23 gives users the possibility to deny apps access to certain functionalities I wanted to update one of my apps to request permissions as it is described in here: https://developer.android.com/preview/features/runtime-permissions.html . In one of the activities I embed a SupportMapFragment . To make it work you need to have the WRITE_EXTERNAL_STORAGE permission, so I request it when I start the activity which results in a creation of a permission request dialog. Now the problem is that when the dialog is still open and I rotate the device the activity will be restarted

what's wrong with my sensor monitoring technique?

做~自己de王妃 提交于 2019-12-03 03:32:33
(please read UPDATE 3 at the end)I'm developing an app that continually works with the sensors of device, works with Accelerometer and Magnetic sensors to retrieve the orientation of device(the purpose is mentioned here ). in other words, my app needs to know the orientation of device in Real-time(however this is never possible, so as fast as possible instead, but really as fast as possible !). as mentioned in professional Android 4 Application Development by Reto Meier : The accelerometers can update hundreds of times a second... I must not lose any data that sensors report and I also want to

Fragment/Activity Lifecycles and Orientation Change

扶醉桌前 提交于 2019-12-03 00:58:19
Fragments are funny things but, so I thought, once you know their quirks they're an invaluable tool for writing good code across multiple devices. However, while fixing an orientation change bug I've run up against a wall. For my fragment to work it needs access to a View which belongs to it's containing Activity leading me on a merry chase trying to find how the Activity & Fragment lifecycles interact. I'm adding a fragment to my Activities view in it's onCreate() method: // Only add a fragment once, as after it's been added it cannot be replaced (Even though there is a .replace() method.

DialogFragment callback on orientation change

被刻印的时光 ゝ 提交于 2019-12-02 21:38:55
I'm migrating my dialogs, currently using Activity.showDialog(DIALOG_ID); , to use the DialogFragment system as discussed in the android reference . There's a question that arose during my development when using callbacks to deliver some event back to the activity/fragment that opened the dialog: Here's some example code of a simple dialog: public class DialogTest extends DialogFragment { public interface DialogTestListener { public void onDialogPositiveClick(DialogFragment dialog); } // Use this instance of the interface to deliver action events static DialogTestListener mListener; public

Javascript doOnOrientationChange :can't fix a bug loading the page

扶醉桌前 提交于 2019-12-02 03:28:50
I used a .js to avoid landscape view from mobile device. I edited a white full-screen image saying "this site is not thought to be viewed in landscape mode, please turn your device" to be shown each time I rotate my device from portrait to landscape. It works except when I load a page and I'm already in landscape mode. Any idea on how to fix it? Thanks <script> (function() { 'use strict'; var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return navigator

How to handle orientation change easily

佐手、 提交于 2019-12-02 00:42:00
问题 I'm working on a android application that adds every view programmaticaly. When the user turns the screen, I just want to values that are filled in to be displayed again. Is there an easy way to let Android do this automaticaly? My application is completely dynamic so it doens't have a predetermined layout, which makes it a lot harder. So, how can I easily save the state of my screen? 回答1: Everytime orientation change, android create new view and destroy the old one. You can saved your data

How to handle orientation change easily

故事扮演 提交于 2019-12-01 23:20:58
I'm working on a android application that adds every view programmaticaly. When the user turns the screen, I just want to values that are filled in to be displayed again. Is there an easy way to let Android do this automaticaly? My application is completely dynamic so it doens't have a predetermined layout, which makes it a lot harder. So, how can I easily save the state of my screen? Everytime orientation change, android create new view and destroy the old one. You can saved your data when orientation change and re-initialize when the new view is created Use onConfigurationChanged method of