I made a Splashscreen it carries and it does not go to the Activity prixima what should I do?

Asked

Viewed 109 times

1

What I must do ?

inserir a descrição da imagem aqui

intro.java

public class intro extends AppCompatActivity {
    protected static final int TIMER_RUNTIME =5000;

    protected boolean mbActive;
    protected ProgressBar mProgressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.intro);
        mProgressBar = (ProgressBar) findViewById(R.id.barrinha);

        final Thread timerThread = new Thread() {
            @Override
            public void run() {
                mbActive = true;
                try {
                    int waited = 0;
                    while (mbActive && (waited < TIMER_RUNTIME)) {
                        sleep(5);
                        if (mbActive) {
                            waited += 5;
                            updateProgress(waited);
                        }
                    }
                } catch (InterruptedException e) {
                    //Caso erro!!f
                } finally {
                    onContinue();
                }
            }
        };
        timerThread.start();

    }
    public void updateProgress(final int timePassed) {
        if (null != mProgressBar) {
            final int progress = mProgressBar.getMax() * timePassed / TIMER_RUNTIME;
            mProgressBar.setProgress(progress);
        }
    }

    public void onContinue() {
        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();

    }
}
  • In what part does it give error ? its Log. d is called ?

  • I may be mistaken, but perhaps the problem is that your Intent is called in a different Thread, I believe that the Intent should be called in the main thread

  • No error just don’t jump to next screen after you load

  • I don’t know exactly why another Task is used to start the other Task Force, try to do this without putting it in another thread

3 answers

1

Try to customize your code as much as possible using a few lines of code. Take a look below at how I do a Splashscreen.

Class

Note: Don’t forget to finish the Activity using finish(), so that it is not possible to return 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

This way I can also use the NoTitleBar.Fullscreen that 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>

0

I don’t quite understand your code, but this is possible to do with AsyncTask !

Follow 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 rotate it, call as follows in the method onCreate:

new Loader().execute((Void)null);

-2

Guys I took the progresseBar and worked and relatively was not so useful to me!

  • 1

    This information could be added as a comment. It is not the solution to the problem, but a "work arround".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.