Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to stop activity recreation on screen orientation?

Tags:

People also ask

How do I stop Android from restarting activity when changing orientations?

Prevent Activity to recreated Another most common solution to dealing with orientation changes by setting the android:configChanges flag on your Activity in AndroidManifest. xml. Using this attribute your Activities won't be recreated and all your views and data will still be there after orientation change.

How do I manage changes to screen orientation?

If you want to manually handle orientation changes in your app you must declare the "orientation" , "screenSize" , and "screenLayout" values in the android:configChanges attributes. You can declare multiple configuration values in the attribute by separating them with a pipe | character.

What happens when screen orientation changes in Android?

When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them . Android does this so that your application can reload resources based on the new configuration.


how i can stop the restarting or recalling of on create() on screen orientation ,i want to stop the recreation of activity on screen orientation. thanks in advance please tell me any better solution its really creating a problem. like in my program i am selecting some picture but on screen orientation the image goes off so thats why i want to stop the recreation of activity on screen orientation.

enter code here
public void onCreate(Bundle savedInstanceState) 
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainwindow);
    Toast.makeText(getApplicationContext(),"a", 1).show();

    bitmap = (Bitmap)getLastNonConfigurationInstance();
    //Toast.makeText(getApplicationContext(),"a1", 1).show();

    if (savedInstanceState != null) 
    {
        bitmap=BitmapFactory.decodeFile(mImageCaptureUri.getPath());
        Toast.makeText(getApplicationContext(),"preview have value", 1).show();
        preview.setVisibility(View.VISIBLE);
        From_Folder.setVisibility(View.GONE);
        From_Camera.setVisibility(View.GONE);
        preview.setImageBitmap(bitmap);


    }