尝试违反锁定任务模式

时间:2018-10-25 07:11:55

标签: android

我有ActivityA,ActivityB,BaseActivity和CloseActivity。下面是我的代码。

public class ActivityA extends BaseActivity {
   protected void onCreate(Bundle savedInstanceState) {    
        startLockTask();
   }

 public void onButtonClicked(View view) {
    switch (view.getId()) {
        case R.id.languageBtn:
             startActivity(new Intent(this, ActivityB.class));
        default:
             break;
        }
  }
   protected void onDestroy() {
        stopLockTask();
    }

}

public class ActivityB extends BaseActivity {

   protected void onCreate(Bundle savedInstanceState) {    
      setContentView();  
   }  

  public void onButtonClicked(View view) {
        switch (view.getId()) {
            case R.id.someBtn:
                clodeDialog();
            default:
                break;
        }
    }
}

public class BaseActivity extends Activity {

   protected void onCreate(Bundle savedInstanceState) {    
       setContentView();
   }

   clodeDialog(){
      clodeDialog(null);
   }

   clodeDialog(Intent broadcastIntent){      
        Intent intent = new Intent(this, CloseActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(CloseActivity.BROADCAST_INTENT_EXTRA, broadcastIntent);        
        startActivity(intent);
   }

}

从这里我启动CloseActivity。但我得到以下消息 startActivityUnchecked:尝试违反锁定任务模式。无法启动CloseActivity。是什么原因。

1 个答案:

答案 0 :(得分:0)

我在调用stopLockTask之前在clodeDialog方法中使用了startActivity

clodeDialog(Intent broadcastIntent){      
        Intent intent = new Intent(this, CloseActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(CloseActivity.BROADCAST_INTENT_EXTRA, broadcastIntent); 
        stopLockTask       
        startActivity(intent);
   }

到此,我解决了这个问题。