新意图不会在onLongPress内部开始?

时间:2012-11-08 11:04:11

标签: android android-intent ondraw

我为表面视图创建了一个TapGestureDetector类。我抓住了Long touch事件,我想开始一个新的活动。但是它无法正常工作。意图没有开始。有一个空指针异常。我已经在清单中定义了操作以及意图。但是有一个我无法识别的错误。

 public class TapGestureDetector extends GestureDetector.SimpleOnGestureListener {

int touchX;
int touchY;
public static String block_name;
Context ctx = custom.ctx;
ArrayList<Rect> rectangles = storeMap.GetArrayList();


@Override
public void onLongPress(MotionEvent event) {

//Detect touched X.Y
    touchX = (int) event.getX();
    touchY = (int) event.getY();
//Go through a set of rectangles and identify the touched rectangle
    for (int i = 0; i < rectangles.size(); i++) {

        if (rectangles.get(i).contains(touchX, touchY)) {

            rectangles.get(i).describeContents();
            String Selected_rect = String.valueOf(rectangles.get(i));
            Store_Identified_Block.Store(Selected_rect);
            getSelectedCoordinates();


            //Start a new intent
            Intent myIntent = new Intent("android.intent.action.zoomlevel");
            myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            //This is not working
            try {
                ctx.startActivity(myIntent);
            } catch (Exception e) {

                Log.d("onLongPress(MotionEvent event)", e.toString());
                e.printStackTrace();
            }



            break;
        }
    }

super.onLongPress(event);
}

1 个答案:

答案 0 :(得分:0)

解决了它:)

try {

                Intent mm=new Intent(finalmainvclass.maincontaxt,zoomlevel.class);
                mm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                finalmainvclass.maincontaxt.startActivity(mm);

            } catch (Exception e) {

                Log.d("MYLOG", "Error is "+e.toString());
                e.printStackTrace();
            }