开始新活动不会暂停当前

时间:2016-08-30 00:15:34

标签: java android android-activity onpause

在我的代码中我正在调用一个新活动,但旧的活动没有暂停

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        float x = event.getX();
        float y = event.getY();
        float[] userCordinates = new float[2];

        userCordinates[0] = x;
        userCordinates[1] = y;
        userSequence.add(userCordinates);
        for (int r = 0; r < copySeq.size(); r++) {
            ImageView iv = (ImageView) (findViewById((Integer) copySeq.get(r)));
            int[] loc = new int[2];
            iv.getLocationOnScreen(loc);
            float xRangeMax = iv.getRight();
            float xRangeMin = iv.getLeft();
            float yRangeMax = iv.getBottom();
            float yRangeMin = iv.getTop();

            Integer point = (Integer)copySeq.get(r);

            if (x <= xRangeMax && x >= xRangeMin
                && y <= yRangeMax && y >= yRangeMin) { 
                if(copyColor.get(r).equals("green")){
                Intent intent = new Intent(this, ChildLevel.class);
    startActivity(intent);
            }
            break;
        }
    }
}

当新的Activity启动时,当前Activity中的代码片段被执行但是当我回来时它应该被执行。例如。这个Activity应该暂时停止。

    if (userSequence.size() >= finalSequence.size()) {
        childLevel=false;
        save();
        check(userSequence);
        touchView.setEnabled(false);
    }
}    
return false;

有谁能告诉我我做错了什么?谢谢!

1 个答案:

答案 0 :(得分:1)

当你开始WITH Booking AS (SELECT * FROM (VALUES ( 1 , '06/01/2016', 2 ) , ( 1 , '06/02/2016', 1 ) , ( 2 , '06/03/2016', 2 ) , ( 3 , '06/03/2016', 4 ) ) x (id, date, hours) ) , lookupid AS ( SELECT DISTINCT id FROM Booking ) , lookupCalender AS ( SELECT DISTINCT date FROM Booking ) SELECT ID.id, Cal.Date, ISNULL(B.Hours,0) AS hours FROM lookupid id INNER JOIN lookupCalender Cal ON 1 = 1 LEFT JOIN Booking B ON id.id = B.id AND Cal.date = B.Date ORDER BY ID.id, Cal.Date 活动时,当前的活动(让我们称之为ChildLevel)暂停(调用MainActivity方法)。

如果您希望在返回onPause()时执行第二个代码段,请将该代码放在MainActivity

中的onResume()方法中

编辑:所以,当您从MainActivity返回MainActivity时,您只需要执行该段代码。您需要使用ChildLevel

startActivityForResult(),而不是MainActivity,请使用startActivity()

startActivityForResult()

然后,在ChildLevel中,当你想回去时:

Intent intent = new Intent(this, ChildLevel.class);
startActivityForResult(i, 123);

最后,在MainActivity中:

Intent returnIntent = new Intent();
setResult(Activity.RESULT_OK, returnIntent);
finish();