我是 android 新手,我在我的 android 项目中创建了一个类,而不是默认的 MainActivity 类,我想用该文件启动我的项目。这是我添加到清单文件中的内容:
<activity
android:name="com.example.surfaceview.SurfaceViewExample"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SURFACEVIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我创建的课程:
public class SurfaceViewExample extends Activity implements OnTouchListener {
OurView v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
v=new OurView(this);
setContentView(v);
v.setOnTouchListener(this);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
v.pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
v.resume();
}
public class OurView extends SurfaceView implements Runnable{
Thread t = null;
SurfaceHolder holder;
boolean isItOK=false;
public OurView(Context context) {
super(context);
holder=getHolder();
}
@Override
public void run() {
while(isItOK){
if(holder.getSurface().isValid()){
continue;
}
Canvas c = holder.lockCanvas();
c.drawARGB(255, 155, 155, 10);//canvas backgroundu boyama
holder.unlockCanvasAndPost(c);
}
}
public void pause(){ //pause the thread
isItOK=false;
while(true){
try{
t.join();
}catch(InterruptedException e){
e.printStackTrace();
}
break;
}
t=null;
}
public void resume(){ //resume the thread
isItOK=true;
t=new Thread(this); //this parameter means use this run method
//which is inside that class
t.start();
}
}
@Override
public boolean onTouch(View v, MotionEvent me) {
return false;
}
}
但是应用程序没有启动。我认为问题可能出在意图过滤器内的那一行:
<action android:name="android.intent.action.SURFACEVIEW" />
谁能帮我这个?
谢谢