爲什麼你想在你的方向改變時開始一個新的活動? 最好爲不同的配置提供不同的資源!或者在1 Activity中使用Fragments。
更多信息可以在這裏找到:
編輯: 您只需創建,再現本身的方向改變一個活動。因此,請刪除您在AndroidManifest.xml中的任何configChanges="screenSize..."
。 在活動的xml文件中,您可以鏈接到另一個片段。 同樣,有關這方面的更多信息可以在上面的鏈接中找到。
MyActivity.java
public class MyActivity extends Activity
{
@Override
public void onCreate(Bundle cycle)
{
super.onCreate(cycle);
this.setContentView(R.layout.myactivity);
}
}
RES /佈局/ myactivity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.TimeFrameGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
而RES /佈局,土地/ myactivity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.example.myapp.fragments.AllDataGraphFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
請參閱此鏈接 - http://stackoverflow.com/questions/12983792/how-to-switch-to-other-activity-at-orientation-change-and-then-back-again – NarendraJi