2013-04-05 47 views
1

我已经为我的应用程序中的所有活动提供了清单中的所有权限,但我的活动在旋转手机时重新开始。重新启动解散我的警报框,再次调用Web服务器获取数据和活动确实保持了以前的状态。我曾尝试过所有可能性,但无法获得解决方案。我该如何解决这个问题?在android中旋转手机时警告对话框被取消

@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>` 
+1

http://developer.android.com/guide/topics/resources/runtime-changes.html – RobinHood 2013-04-05 05:06:14

+0

你必须要求两种模式? – Harshid 2013-04-05 05:12:39

+0

是的,我需要两种模式 – SathishKumar 2013-04-05 05:14:00

回答

0

这是正常的行为。从处理运行时变化的android文档:

“某些设备配置可能会在运行时更改(如屏幕方向,键盘可用性和语言),当发生此类更改时,Android会重新启动运行Activity(onDestroy()称为onCreate()),重新启动行为旨在通过使用与新设备配置匹配的备用资源自动重新加载应用程序来帮助您的应用程序适应新的配置。

here

1

您可以尝试以保存和使用方法来恢复活动状态的onSaveInstanceState()和onRestoreInstanceState()。

请参阅here阅读更多关于它。

查看问题here

编辑 例如: 如果您正在使用的WebView你可以这样做:

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

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

我会推荐阅读:Android - Preventing WebView reload on Rotate
还可以阅读:How to prevent WebView auto refresh when screen rotation

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

加这对您的清单中的活动元素

<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>` 
+1

在清单中添加screenSize – 2013-04-05 05:09:01

+0

我不知道为什么,我的清单不支持screenSize。 – SathishKumar 2013-04-05 05:17:12

+0

@SathishKumar只有在开发** API级别13 **或更高级别时才需要'screenSize'属性。 – Renjith 2013-04-05 05:23:48

0

那不是一个问题,因为视图需要重绘活动重新开始按照新的orientation..This画是按照Android文档.. 反正你可以为取向的变化onconfigChanges注册在你的清单,并办理在自己..

+0

我该如何处理该问题,因为我的应用程序从网页获取数据。在旋转手机时,再次拨打网页以获取数据,以及警报框也被解除。很多麻烦,我该如何解决这些问题。请给出一些想法谢谢 – SathishKumar 2013-04-05 05:22:50

+0

请张贴您的活动代码.. – Akhil 2013-04-05 07:03:16

0

添加

android:configChanges="orientation|keyboardHidden"

您相应的活动,这WIL我解决你的问题。

希望它有帮助。

+0

是的,我已经给,但没有工作。 – SathishKumar 2013-04-05 05:23:52