【发布时间】:2020-12-11 16:15:52
【问题描述】:
我有以下代码,想知道在onCreate() 之前调用了什么,因为它在调用活动(选项卡式活动)之前显示空白屏幕。有什么办法可以避免出现黑屏?
我什至不能使用 onAttach,因为我的类正在扩展 AppCompatActivity 并实现 OnMapReadyCallback,PlaceSelectionListener。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabbed);
TabHost tab = (TabHost) findViewById(R.id.tabHost);
tab.setup();
TabHost.TabSpec spec1 = tab.newTabSpec("Search");
spec1.setIndicator("Search");
spec1.setContent(R.id.layout1);
tab.addTab(spec1);
TabHost.TabSpec spec2 = tab.newTabSpec("Settings");
spec2.setIndicator("Settings");
spec2.setContent(R.id.layout2);
tab.addTab(spec2);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getBestProvider(new Criteria(), false);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
}
【问题讨论】:
-
如果片段
onAttach()在onCreate()之前被调用。 refer this -
我的班级正在扩展 AppCompatActivity 并实现 OnMapReadyCallback、PlaceSelectionListener。所以我不能使用 OnAttach()
-
可能是Application类?
-
在调用任何
Manifest.xml之前 -
那么这可能是由于您的应用程序实例的实例化。为避免这种情况,请尝试在其他线程中进行更繁重的工作。
标签: java android android-studio