2

我制作了一个启动图像以在我的活动开始时显示。图像显示完美。但问题是当我调用它时

public class SplashImageActivity extends Activity {
    protected boolean active = true;
    protected int splashTime = 5000; // time to display the splash screen in ms

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        // thread for displaying the SplashScreen
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(active && (waited < splashTime)) {
                        sleep(100);
                        if(active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    startActivity(new Intent(SplashImageActivity.this,Myapps.class));
                    finish();
                    //startActivity(new Intent("com.splash.com.MyApps"));
                    //startActivity( new Intent(getApplicationContext(), Myapps.class));
                }
            }
        };
        splashTread.start();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            active = false;
        }
    return true;
    }
}

去下一个活动stop()不起作用。它不去这个活动。我在清单中添加所有活动。在这样的stop()代码中显示

在此处输入图像描述

有什么问题?

4

5 回答 5

5

开始活动后无需调用 stop() 和调用 finish()

finally 
{

    startActivity(new Intent(currentclass.this,nextActivity.class);
    finish();
}
于 2012-06-25T05:28:44.027 回答
2

我使用线程来显示启动画面,它对我有用:

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

    mSplashThread =  new Thread(){
        @Override
        public void run(){
            try {
                synchronized(this){
                    wait(4000);
                }
            }catch(InterruptedException ex){                   
            }
            finish();

            Intent i=new Intent(getApplicationContext(),NextActivity.class);
            startActivity(i);

            interrupt();
        }

    }; 
    mSplashThread.start();        
}
于 2012-06-25T05:30:53.060 回答
1

请尝试以下代码..

public class Splashscreen extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Thread t2 = new Thread() {
                public void run() {
                    try {
                        sleep(2000);
                        startActivity( new Intent(getApplicationContext(), Exercise.class));
                        finish();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            t2.start();
        }
    }
于 2012-06-25T05:27:22.770 回答
0

首先它不是 Activity 的 onStop 所以看起来你正在调用线程的停止函数,这就是Deprecated为什么你得到罢工线所以使用其他方式来停止使用更好的方式来实现启动的线程...... .

看起来你尝试一些类似这个链接的东西

于 2012-06-25T05:21:44.493 回答
0

无需调用 stop() 只需在开始活动后调用 finish()

finally {
startActivity(new Intent(currentclass.this,nextActivity.class);
finish();
}

您还可以使用处理程序 postdelayed() 来制作如下所示的启动画面

 public class SplashScreenActivity extends Activity{

        private Handler handler;

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

            final Runnable runnable = new Runnable() {

                @Override
                public void run() {
                       Intent intent=new Intent(SplashScreenActivity.this, nextActivity.class);
                       startActivity(intent);
                       finish();

                }
            };
            handler = new Handler();
            handler.postDelayed(runnable, 5000);


        }

    }

您将显示启动屏幕 5 秒钟,然后移动到下一个活动

于 2012-06-25T05:35:11.923 回答