0

我有 4 个活动:changeView、changeViewTwo、NoRunning、YesRunning。另外,我有 2 个 XML:yes_running 和 no_running

第一个屏幕(no_running)有一个按钮,可以像这样改变视图:

Button buttonchange01 = (Button) findViewById(R.id.Button01);
    buttonchange01.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new     Intent("com.example.runningtimer.changeView"));
        }
    });

在清单上

<activity
        android:name="changeView"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.runningtimer.changeView" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

在 changeView.java 上

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yes_running);
}

这是正确完成的,但是,当新的出现时,我有一个计数为 10 的进度条,它应该回到 no_running.xml 但它没有,这就是 YesRunning 活动的样子

public class YesRunningActivity extends Activity {

ProgressBar myProgressBar;
int myProgress = 0;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yes_running);
    myProgressBar=(ProgressBar)findViewById(R.id.progressbar_Horizontal);
    new Thread(myThread).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.no_running, menu);
    return true;
}
public Runnable myThread = new Runnable(){

    @Override
    public void run() {
        // TODO Auto-generated method stub
        while (myProgress<100){
            try{
                myHandle.sendMessage(myHandle.obtainMessage());
                Thread.sleep(100);
            }
            catch(Throwable t){ }
        }
        if (myProgress==100){
            finish();
            startActivity(new Intent("com.example.runningtimer.changeViewTwo"));
            myProgress = 0;
        }
    }

    Handler myHandle = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            myProgress++;
            myProgressBar.setProgress(myProgress);
        }
    };
};
}    

changeViewTwo 的清单

<activity
        android:name="changeViewTwo"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.runningtimer.changeViewTwo" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

更改视图二

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.no_running);
}

知道为什么它不回去了吗?或者我怎样才能让它回去?

4

0 回答 0