[英]Intent constructor arguments undefined
我想开始一项活动,所以我选择了这种上课方式。 我知道我可以通过直接在intent构造函数中传递ACTION NAME来轻松做到这一点,但是我正在学习android,因此我尝试学习新方法。 我在另一个类中用相同的代码开始了另一个活动,并且在那里工作,但是在这里出现了以下错误。 我认为这与THREAD类有关。
错误是:
The constructor Intent(new Thread(){}, Class) is undefined.
我该如何解决? 这是代码:
package com.umer.practice2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashScreen extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Thread timer= new Thread()
{
public void run()
{
try
{
sleep(5000);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
Class ourclass = Class.forName("com.umer.practice2.StartingPoint");
Intent myintent= new Intent(this,ourclass); // error
startActivity(myintent);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
这是给出强制关闭错误的类活动的布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="hint"
android:id="@+id/fdisp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="How many times you eat in a day"
android:gravity="center"
android:id="@+id/but3"
/>
</LinearLayout>
这是该类本身的代码
package com.umer.practice2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MyClass extends Activity{
Button b3;
TextView disp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
b3= (Button) findViewById(R.id.but3);
disp= (TextView) findViewById(R.id.fdisp);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
disp.setText("It depends ");
}
});
}
}
只需将意图创建替换为:
Intent myintent= new Intent(SplashScreen.this, StartingPoint.class);
否则, this
是指封闭的Thread
类
您可以按以下方式致电
startActivity(new Intent(SplashScreen.class, StartingPoint.class);
会的。 试试吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.