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);
}
This is happening because when screen orientation rotates the Activity gets re-started. In this case you can add
configChanges
attribute in your tag in the AndroidManifest file to stop the re-creation of the Activity.By, this also it won't stop though the orientation changes.
In your AndroidManifest.xml file, in the activity add
Example as below:
Two ways for this:
Either you can set android:configChanges="keyboardHidden|orientation" in Manifest file to avoid recreation of activity.
Or Make the changes you want to apply on changing the orientation inside the overrided method
@Override
Add
or
to your layout in
mainwindow.xml
.Example:::
No need to add anything in Activity class.
Hope this may help you
There are a more full list of parameters for prevent activity recreations (in Manifest.xml):
Not the best, but maybe the easiest solution is to add
to youractivity in your manifest so it looks like