如何启动后一定时间内的活动?

编程入门 行业动态 更新时间:2024-10-13 14:26:19
本文介绍了如何启动后一定时间内的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要经过一定的时间段,开始从当前活动的活性。我codeD像下面。

i need to start an activity from the current activity after a certain time period. I coded like below.

public class FirstActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); new Timer().schedule(new TimerTask(){ public void run() { startActivity(new Intent(FirstActivity.this, SecondActivity.class)); } }, 2000); }

但它不是working..it不断崩溃。是我的方法正确吗?我的清单文件如下

But its not working..it keeps on crashing.. Is my method correct? my manifest file is as below

`

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".FirstActivity" android:label="@string/title_activity_first" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SecondActivity" android:label="@string/title_activity_second" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.first.FirstActivity" /> </activity> </application>

推荐答案

您可以使用 处理程序类 postDelayed()方法执行这样的:

You can use the Handler class postDelayed() method to perform this:

Handler mHandler = new Handler(); mHandler.postDelayed(new Runnable() { @Override public void run() { //start your activity here } }, 1000L);

在哪里1000L是以毫秒为单位的时间之后,code Runnable接口类中 将被调用。

Where 1000L is the time in milliseconds after which the code within the Runnable class will be called.

尝试使用此。

更多推荐

如何启动后一定时间内的活动?

本文发布于:2023-11-27 13:29:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638273.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间内   后一定

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!