多个活动问题

时间:2013-03-07 17:16:32

标签: android android-activity progress-bar progress

我有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>

changeViewTwo

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

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

0 个答案:

没有答案