我的MainActivity在应用程序首次加载时显示welcomeScreen片段。当用户单击开始按钮时,它会切换到MainScreen Fragment。如果先前已按下开始按钮,如何跳过welcomeScreen片段?
MainActivity.java:
import layout.WelcomeScreenFragment;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
SearchView searchView;
final static String[] NEEDED_PERMISSIONS = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
if (ContextCompat.checkSelfPermission(getApplicationContext(), NEEDED_PERMISSIONS[0])
!= PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(getApplicationContext(), NEEDED_PERMISSIONS[1])
!= PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(getApplicationContext(), NEEDED_PERMISSIONS[2])
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, NEEDED_PERMISSIONS, 808);
Log.i(TAG, "onCreate: Requesting Permissions");
}
// Makes sure that the root_layout view is not null before doing anything
if (findViewById(R.id.root_layout) != null) {
// Makes sure that there's no saved instance before proceeding
if (savedInstanceState == null) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction manager = fm.beginTransaction();
manager
.add(R.id.root_layout, WelcomeScreenFragment.newInstance(), "welcomeScreen")
.commit();
}
}
}