我的活动流程有问题。流程如下:
Splash -> MainMenu -> Launching -> Starting -> Instructions -> MagicPower
因此,在 MagicPower 活动中,我想在 sleep() 时间后回到 MainMenu!问题是 MainMenu 活动根本没有完成并且显示了两次。我该如何克服这个问题!正如我一直在尝试的那样:
package com.app.imagic;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MagicPower extends Activity {
///////////
private TextView lookme;
private volatile boolean running=true;
private int i;
private TextView gone;
///////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_magic_power);
lookme=(TextView)findViewById(R.id.LOOK);
lookme.setVisibility(View.INVISIBLE);
gone=(TextView)findViewById(R.id.GONE);
gone.setVisibility(View.INVISIBLE);
Typeface face=Typeface.createFromAsset(getAssets(), "fonts/crazy.TTF");
gone.setTypeface(face);
lookme.setTypeface(face);
//////////////////////////////////////////////////////////
runThread();
}
//////////////////////////////////////////////////////////////
private void runThread() {
new Thread() {
public void run() {
while(running){
while ( i++ < 4) {
if(i==3){
Intent intent = new Intent(getApplicationContext(), MainMenu.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
startActivity(new Intent(MagicPower.this,MainMenu.class));
running=false;
finish();
break;
}
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(i==1){
lookme.setVisibility(View.VISIBLE);
}
if(i==2){
gone.setVisibility(View.VISIBLE);
}
}
});
Thread.sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
}
}
}
}.start();
}
///////////////////////////////////////////////////////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.magic_power, menu);
return true;
}
@Override
public void onBackPressed() {
// do nothing.
}
}
应该是 MainMenu 之后的样子;MainMenu Activity 不应再次出现在屏幕上!请帮助我提前谢谢