1

I had give all the permission in my manifest for all the activities in my app but my activity re-starting while rotating my phone. That restart dismissing my alert box, again calling web server for fetching data and activity does maintain the previous state. I had tried with all the possibilities but can not get solution. How can i fix this issue?

@Override
public void onCreate(Bundle savedInstanceState) 
{       
    super.onCreate(savedInstanceState);  
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.station_list_layout);

    ConstantValues.CURRENT_ACTIVITY=StationListActivity.this;

    ConstantValues.NEAREST_PLACE_MENU_SLIDER_FLAG=false;
    ConstantValues.MESSAGE_MENU_SLIDER_FLAG=false;
    ConstantValues.STATION_LIST_MENU_SLIDER_FLAG=true;

    orientation=getResources().getConfiguration().orientation;
    userAndMessageCount=new UserAndMessageCount();
    ((TextView)findViewById(R.id.stationlist_route_name)).setText(ConstantValues.ROUTE_NAME);
    list = (ListView) findViewById(R.id.myListView);  
    Cursor cursor=new UpdateLocalDatabase().getStationNameByRoute();
    adapter=new StationListAdapter(StationListActivity.this, cursor);
    adapter.notifyDataSetChanged();

    if(!ConstantValues.STATION_LIST_LOATED)
        userAndMessageCount.execute();
    else
    {
        Footer.setMsgCount(ConstantValues.MSG_COUNT);
        Footer.setUserCount(ConstantValues.FAVORITE_STATION_LIST.size());
        list.setAdapter(adapter);
    }

} 
         <activity 
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="unspecified"
            android:name=".LaunchingPageActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>`
SathishKumar
  • 1,644
  • 1
  • 14
  • 28

5 Answers5

4
android:configChanges="keyboardHidden|orientation|screenSize"

add this to your activity element in manifest

Like

<activity 
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="unspecified"
            android:name=".LaunchingPageActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>`
Arun C
  • 9,035
  • 2
  • 28
  • 42
1

You may try to save and restore the state of an Activity using the methods onSaveInstanceState() and onRestoreInstanceState().

See here to reading more about it.

See question here.

Edit For example: If you are using webview you may do something like:

@Override
protected void onSaveInstanceState(Bundle outState )
{
    super.onSaveInstanceState(outState);
    web.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
   super.onSaveInstanceState(savedInstanceState);
   web.restoreState(savedInstanceState);
} 

I would recommend reading : Android - Preventing WebView reload on Rotate
Also read : How to prevent WebView auto refresh when screen rotation

Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
0

That's normal behaviour. From the android docs on handling runtime changes:

"Some device configurations can change during runtime (such as screen orientation, keyboard availability, and language). When such a change occurs, Android restarts the running Activity (onDestroy() is called, followed by onCreate()). The restart behavior is designed to help your application adapt to new configurations by automatically reloading your application with alternative resources that match the new device configuration."

See here

Keith Coughtrey
  • 1,386
  • 13
  • 17
0

Thats not an issue, as view needs to be redrawn activity is restarted to draw according to new orientation..This is as per Android documentation.. Anyway you can register for orientation change onconfigChanges in your manifest and handle at your own..

Akhil
  • 6,667
  • 4
  • 31
  • 61
  • How can I handle that because my app fetching data from web. While rotating phone it again call web for fetch data,as well as alert box also dismissed. Lot's of troubles how can i fix those. Please give some idea thank you – SathishKumar Apr 05 '13 at 05:22
0

add

android:configChanges="orientation|keyboardHidden"

to your corresponding activity, this will resolve your issue.

Hope it helps.

Harshid
  • 5,701
  • 4
  • 37
  • 50