Reputation: 10777
I am new to android and i have created a class in my android project other than the default MainActivity class and i want to start my project with that file. Here is what i added to my manifest file:
<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>
And the class that i created:
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;
}
}
But the application does not start. I think the problem might be in that line inside the intent filter:
<action android:name="android.intent.action.SURFACEVIEW" />
Can anyone help me with this?
Thanks
Upvotes: 0
Views: 90
Reputation: 9599
Update your manifest with the following code for your activity. This should now launch your activity.
<activity
android:name="com.example.surfaceview.SurfaceViewExample"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I hope this helps.
Upvotes: 1