I made a SplashScreen it loads and will not go to the first activity what should I do? [closed]

1

What should I do?

intro.java

publicclassintroextendsAppCompatActivity{protectedstaticfinalintTIMER_RUNTIME=5000;protectedbooleanmbActive;protectedProgressBarmProgressBar;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.intro);mProgressBar=(ProgressBar)findViewById(R.id.barrinha);finalThreadtimerThread=newThread(){@Overridepublicvoidrun(){mbActive=true;try{intwaited=0;while(mbActive&&(waited<TIMER_RUNTIME)){sleep(5);if(mbActive){waited+=5;updateProgress(waited);}}}catch(InterruptedExceptione){//Casoerro!!f}finally{onContinue();}}};timerThread.start();}publicvoidupdateProgress(finalinttimePassed){if(null!=mProgressBar){finalintprogress=mProgressBar.getMax()*timePassed/TIMER_RUNTIME;mProgressBar.setProgress(progress);}}publicvoidonContinue(){Log.d("messagemFinal", "Sua barra de loanding acabou de Carregar!");

        TimerTask task=new TimerTask() {
            @Override
            public void run() {
                Intent mainIntent=new Intent().setClass(intro.this,main.class);
                startActivity(mainIntent);
                finish();
            }
        };
        Timer timer=new Timer();

    }
}
    
asked by anonymous 27.09.2016 / 19:09

3 answers

1

Try customizing your code as much as possible using a few lines of code. Take a look below how I make a Splashscreen .

Class

Note: Do not forget to end Activity using finish() , so you can not go back to your Splash by clicking onBackPress() .

public class Splash extends Activity implements Runnable {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Handler h = new Handler();
        h.postDelayed(this, 1400);
    }

    @Override
    public void run() {
        startActivity(new Intent(this, Main.class));
        finish(); // finaliza o splahs
    }
}

Manifest

In this way, I can also use NoTitleBar.Fullscreen which will leave in full screen without the toolbar.

        <activity
            android:name="br.com.dekra.smartapp.ui.ApresentacaoInicio"
            android:label="@string/str_splash"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
29.09.2016 / 18:42
0

I do not understand your code very well, but this is possible with AsyncTask !

Here's an example:

class Loader extends AsyncTask<Void, Void, Void>{

    private Integer update = 1;
    @Override
    protected Void doInBackground(Void... params) {

       // iteramos ate 100 
       while (update <= 100){
          // Criamos um Runnable q ira mandar a atualizacao desta Thread par a tela!
           final Runnable runnable = new Runnable() {
               @Override
               public void run() {
                   // seta o valor atualizado na tela
                   progressBar.setProgress(update);
               }
           };
           // executa o Runnable na ThreadUI
           runOnUiThread(runnable);
           update++;
           try {
               Thread.sleep(100);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       }

            return null;

    }

    @Override
    protected void onPostExecute(Void aVoid) {
        // Após abrimos a próxima tela....
        Intent mainIntent=new Intent((intro.this, main.class);
        startActivity(mainIntent);
        finish();
    }
}

To run it, call this method as onCreate :

new Loader().execute((Void)null);
    
29.09.2016 / 18:33
-2

People I took progresseBar and it worked and relatively it was not so useful for me!

    
30.09.2016 / 14:30