Android how to prevent restart the activity on orientation change.

For manual orientation change:

[php]
<activity
android:name=".ActivityName"
android:configChanges="orientation"/>
[/php]

[php]

public class ActivityName extends Activity {

onStart() {
setRequestedOrientation(orientation);
}
onConfigurationChanged(Configuration newConfig){
// do stuff for orientation change.
}
onClick() {
setRequestedOrientation(orientation);
}
}

[/php]

For auto-orientation detect:

[php]
<activity
android:name=".ActivityName"
android:configChanges="orientation"/>

[/php]

[php]

public class ActivityName extends Activity {

onConfigurationChanged(Configuration newConfig){
// do stuff for orientation change.
}
}
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Error:Execution failed for taskError:Execution failed for task

Error:Execution failed for task ‘:app:transformDexArchiveWithDexMergerForDebug’. > com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/measurement/zzws;   update the google-service plugin to: classpath ‘com.google.gms:google-services:3.3.0’

Android Encryption and Decryption String with AES/DES .Android Encryption and Decryption String with AES/DES .

Base Class :  import android.util.Base64; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; /**