List disappears when phone rotated(Android) - java

In my app, in the OnCreate method, I create a list(using an add button) or I fetch it from a saved file. My function works fine and I am able to create and fetch the list until I rotate the phone(vertical -> horizontal). The list then disappears. I am still able to click the buttons on screen, but it seems I have no items in the list.Any help appreciated. Thank You in advance.

add this tag in Activity tag in manifest
android:configChanges="keyboardHidden|orientation"
and add this in activity code
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
in the same activity..
this happens because each time your screen orientation is changed onCreate() method of the Activity will be called every time

This post from developer.android.com could help too!

It would be wise if you would add screenSize at android:configChanges="keyboardHidden|orientation" aswell i.e
android:configChanges="orientation|keyboardHidden|screensize"

Related

Keyboard break layout and behaviour

I have a fragment with some views like EditText, ViewFlipper and RecyclerView.
But I have an issue with the keyboard: when the keyboard appear, some of my views become whites and my RecyclerView is empty or when I tap on an item I have to scroll him to handle the event.
Do you know why the soft keyboard break the layout and behavior? And do you know how to solve this?
Thanks you for your help.
EDIT : Seems solved
I've found a solution which seems to work:
I change the softInputMode in the onCreate() method to adjustNothing
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
}
then in onDestroy I set the previous mode, here adjustPan
override fun onDestroy() {
super.onDestroy()
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
}
You can simply switch your Activity's windowSoftInputMode flag to adjustPan in your AndroidMainfest.xml file inside your activity tag.
Check the official documentation for more info.
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
<activity
...
android:windowSoftInputMode="adjustPan">
</activity>

Soft-keyboard squeezes textedit box in Android

How can I solve the following issue? What I would like to happen is for the input window to be displaced, not squeezed, by the soft-keyboard.
Add android:windowSoftInputMode="adjustPan" to your activity tag in your AndroidManifest.xml

Android notification bar persists on the all Application screen(never goes)

I have a screen in my app with a button to set date/time in the OS. I use startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS)) to open the android's date/time screen .
After setting the date/time , i return to my app screen using the back button in the android's status(notification) bar. After this, the notification bar never dissappears from my app screens. Its persistent until i restart my application. Is there a way to remove the notification bar?
I have added the line "android:theme="#android:style/Theme.NoTitleBar.Fullscreen" to all my activities and even at at the application level(just inside )
But still it never goes
Here is a part of my manifest
<activity
android:name="com.cyberonics.progsoundapp.ui.AlarmSettingScreen"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_alarm_setting_screen"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
I also have the following code in my activity class
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN) before SetContentView()
Is there anything else i am missing?
Request your guidance on this
Thank you

Disable fadein animation

I am trying to create a splash screen for my app. The problem is it first renders empty layout with default title bar and then fades in my image.
This is all I have onCreate
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.activity_splash);
Attempted solution from switching activities without animation
Also tried to set window attributes
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.windowAnimations = lp.windowAnimations | android.R.attr.windowDisablePreview;
this.getWindow().setAttributes(lp);
neither made any visible difference.
you can get rid of titlebar by setting theme for your splash activity. Add this to declaration of activity in your Manifest
android:theme="#android:style/Theme.NoTitleBar"

how to do haptic feedback when an ImageView is not working

I created an Activity displays an ImageView on the screen. I want get haptic feedback when the image is clicked.
In the main layout main.xml I added the next ImageView tag:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image"
android:src="#drawable/dog"
android:onClick="doBark"
android:hapticFeedbackEnabled="true"/>
Then, in the Activity code I add this method:
public void doBark(View v) {
v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
Log.d("BarkingDog", "is hapticFeedbackEnabled: " + v.isHapticFeedbackEnabled());
}
When I click on the image I can see that doBark() is called and the output of the Logcat says "is hapticFeedbackEnabled: true", but I can't feel anything. I've also tried with the other two HapticFeedback constants, and no luck.
I know that HapticFeedback is enabled because each time I press the menu button, the device vibrates.
Any ideas? Suggestions?
PS: I don't want to use the Vibrator object. By using it, I can make the device vibrate, but I don't think it's the right way to do it.
Take a look at this: http://groups.google.com/group/android-developers/browse_thread/thread/de588e3d15cb9055?pli=1
Do note that it is old though, but the last time I had to use haptic feedback, I followed what Dianne had to say here

Categories