onCreate方法不断得到所谓的设备发生变化时,方向 [英] onCreate method keeps getting called when the orientation of device changes
问题描述
我有一个的AsyncTask
这被称为的onCreate()
在我的主要活动
。在同一个活动
如果方向改变的AsyncTask
被再次调用。我如何prevent这种情况的发生或我怎么调整我的计划,以避免这种情况的发生?
公共类主要扩展活动{
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.pages);
StartProcess sProcess =新StartProcess();
sProcess.execute(本);
}
}
您可以添加安卓configChanges =定向
的活动清单和手动设置的内容查看或通过重写改变布局的<一个href="http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged%28android.content.res.Configuration%29"相对=nofollow> onConfigurationChanged 方法,在你的活动。
I have an AsyncTask
which gets called onCreate()
in my Main Activity
. In the same Activity
if the orientation changes the AsyncTask
gets called again. How do I prevent this from happening or how do I restructure my program to avoid this happening?
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pages);
StartProcess sProcess = new StartProcess();
sProcess.execute(this);
}
}
You can add android:configChanges="orientation"
in the Activity manifest and manually set the contentView or change the layout by overriding the onConfigurationChanged method in your Activity.
这篇关于onCreate方法不断得到所谓的设备发生变化时,方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!