Screen saver shows a blank white screen when running AsyncTask

I have an application that installs an exchange of funds and shows them in RecyclerView.
My application worked fine before I made a simple theme change. I changed it from @android:style/Theme.AppCompat.Light.NoActionBar"

@android:style/Theme.NoTItleBar.Fullscreen
because I wanted to hide the status bar when my application loads at startup.


manifest

        <!-- Splash Screen -->
    <activity android:name=".Splash"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

Class splash

public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 5000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.initial_activity);

    new InitialViewLoad().execute();
}

private class InitialViewLoad extends AsyncTask<Void, Void, Long> {
    @Override
    protected Long doInBackground(Void ... params) {
        long before = System.currentTimeMillis();
        List<Fund> funds = FundPortfolio.get(getApplicationContext()).getFunds();
        new PricesFetcher().fetchItems(funds);
        for (Fund fund : funds) {
            new FinanceFetcher().fetchItems(fund);
            FundPortfolio.get(getApplicationContext()).updateFund(fund);
        }
        long after = System.currentTimeMillis();
        long time = after - before;
        return time;
    }

    @Override
    protected void onPostExecute(Long time) {
        Intent i = new Intent(Splash.this, MainActivity.class);
        synchronized (this) {
            try {
                if (SPLASH_DISPLAY_LENGHT - time > 0) {
                    wait(SPLASH_DISPLAY_LENGHT - time);


         }
                } catch (InterruptedException ioe) {
                    Log.e("Blah,Blah,Blah", "Blah", ioe);
                } finally {
                    startActivity(i);
                    finish();
                }
            }
        }
    }
}

InitialViewLoad().execute();, .
, , Splash Screen , .
RecyclerView ( ), Splash .

, .
, . - , , , .
!


##

initial_activity.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:background="#1b5e20"
              android:gravity="center"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/logo"
        android:layout_gravity="center"/>

</LinearLayout>

2

​​. Timertask

protected void onPostExecute(Long time) {
    final Intent i = new Intent(Splash.this, MainActivity.class);
    handler = new Handler();

    timer = new Timer();
    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    startActivity(i);
                    finish();
                }
            });
        }
    };
    if (SPLASH_DISPLAY_LENGHT - time > 0)
        timer.schedule(timerTask, SPLASH_DISPLAY_LENGHT - time);
    else
        timer.schedule(timerTask, 5000);
}
+4
1

, ... API 23 (Marshmallow)

:

file β†’ settings β†’ build, execution, deployment β†’ Instant Run

+1

All Articles