Java tutorial
/* * Copyright [2017] [zhi] * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.zhi.android.modules.splash; import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityOptionsCompat; import com.zhi.android.common.app.BaseActivity; import java.util.concurrent.TimeUnit; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; /** * Splash activity used to show a transform view when first time start app. * Custom can directly use this class or create his own splash activity, just * let theme inherit BaseTheme_SplashScreen */ public class SplashActivity extends BaseActivity { private Observable<Long> mTimerObservable; @Override @SuppressWarnings({ "CheckReturnValue", "unchecked" }) protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTimerObservable = Observable.timer(1000, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); mTimerObservable.subscribe(aLong -> { mTimerObservable = null; final Intent intent = getIntent(); final Intent nextIntent; if (intent != null && intent.hasExtra(BuildConfig.NEXT_INTENT)) { nextIntent = intent.getParcelableExtra(BuildConfig.NEXT_INTENT); } else { nextIntent = new Intent(Intent.ACTION_MAIN); } nextIntent.addCategory(Intent.CATEGORY_DEFAULT); ActivityCompat.startActivity(SplashActivity.this, nextIntent, ActivityOptionsCompat.makeSceneTransitionAnimation(SplashActivity.this).toBundle()); supportFinishAfterTransition(); }); } }