我在活动开始时制作了一个启动图像。 图像显示完美。但问题是我称之为
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()
在代码中显示如下
问题是什么?
答案 0 :(得分:5)
无需调用stop()并在启动活动后调用finish()
finally
{
startActivity(new Intent(currentclass.this,nextActivity.class);
finish();
}
答案 1 :(得分: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();
}
答案 2 :(得分: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();
}
}
答案 3 :(得分:0)
首先它不是onStop of Activity所以看起来你正在调用线程的停止函数Deprecated
这就是为什么你得到了攻击线所以用其他方法停止使用线程更好的方法来实现飞溅........
看起来你尝试了这样的事情link
答案 4 :(得分: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秒钟,然后转到下一个活动