0

How do I increase timer of the splash screen ? I need it to be slower.

public class MainActivity extends Activity {

private Handler mHandler = new Handler();

ImageView imageview;
int alpha = 255;
int b = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imageview = (ImageView) this.findViewById(R.id.imageView1);     

    imageview.setAlpha(alpha);

    new Thread(new Runnable() {
        public void run() {
            initApp();

            while (b < 2) {
                try {
                    if (b == 0) {
                        Thread.sleep(1000);
                        b = 1;
                    } else {
                        Thread.sleep(50);
                    }

                    updateApp();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }).start();

    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            imageview.setAlpha(alpha);
            imageview.invalidate();

        }
    };

}

public void updateApp() {
    alpha -= 5;

    if (alpha <= 0) 
        {
            b = 2;          
            Intent in = new Intent(this, TabsLayoutActivity.class);
            startActivity(in);
            this.finish();
        }
    mHandler.sendMessage(mHandler.obtainMessage());

}   
public void initApp(){       

}

  }
Siddharth
  • 9,349
  • 16
  • 86
  • 148
lovely guy
  • 51
  • 5

2 Answers2

1

You can also use Handler for splash screen like below..

Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            finish();
            Intent menu = new Intent(getBaseContext(), MainMenu.class);
            startActivity(menu);
        }
    }, 3000);

Here 3000 = 3 seconds.You can replace the time as you needed.Hope it will help you.

AndiM
  • 2,196
  • 2
  • 21
  • 38
  • @lovely guy..Always welcome..:) If answer is true you can accept it. – AndiM Jun 19 '13 at 06:36
  • Yes you can do it..Please refer this link..http://stackoverflow.com/questions/14052209/prevent-uninstall-of-applications-in-android – AndiM Jun 19 '13 at 06:50
0

Increase sleep time

 Thread.sleep(3000);  /// 3000 milli seconds i.e 3 sec 

if you want more just increase that number.

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166