问题描述
我有一个Android应用程序。我想提出一个加载屏幕与进度条。
I have an Android application. I am making a loading screen with a progress bar.
我进入了onCreate方法的延迟。当计时器结束,我要完成当前活动,并开始一个新的。
I entered a delay in the onCreate method. When the timer finishes, I want to finish the current activity and start a new one.
这只是当它调用结束给我一个例外()
方法。
public class LoadingScreen extends Activity{
private LoadingScreen loadingScreen;
Intent i = new Intent(this, HomeScreen.class);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
CountDownTimer timer = new CountDownTimer(10000, 1000) //10 second Timer
{
public void onTick(long l)
{
}
@Override
public void onFinish()
{
loadingScreen.finishActivity(0);
startActivity(i);
};
}.start();
}
}
我怎样才能改变code,使其结束时进度条完成?
How can I change the code so that it ends when the progress bar is done?
推荐答案
如果你正在做一个载入画面,只需将该参数设置为不保持它在活动栈。在您的manifest.xml,在那里你定义您的活动做的:
If you are doing a loading screen, just set the parameter to not keep it in activity stack. In your manifest.xml, where you define your activity do:
<activity android:name=".LoadingScreen" android:noHistory="true" ... />
而在你的code没有必要调用.finish()了。只要做到startActivity(我);
And in your code there is no need to call .finish() anymore. Just do startActivity(i);
也没有必要保持当前活动的实例,在一个单独的领域。您可以随时访问它像 LoadingScreen.this.doSomething()
而不是私人LoadingScreen loadingScreen;
There is also no need to keep a instance of your current activity in a separate field. You can always access it like LoadingScreen.this.doSomething()
instead of private LoadingScreen loadingScreen;
这篇关于如何完成在Android的当前活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!