在消费结果之前检查意图是否为空

Checking whether the intent is empty before consuming the result

我正在从我的 onNewIntent 方法中的 onPostExecute 方法获取一个意图。有时这个意图有价值,只有那时我想显示我的对话框 window 但当前 AlertDialog 正在方法中显示,即使意图为空?我怎样才能避免这种情况,因为我已经在额外检查意图了。

protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);

    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("stop_route")) {

        ArrayList<Integer> routeList = extras.getIntegerArrayList("stop_route");

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
           .
           .
           .

    }
}

onPostExecute 方法:

@Override
protected void onPostExecute(Void result) {
    // Intent with Conetxt of the Asyntask class and
    Intent intent = new Intent(mContext, MainActivity.class);
    intent.putIntegerArrayListExtra("stop_route", routes);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mContext.startActivity(intent);

}

您可以尝试检查: extras.getIntegerArrayList("stop_route").length > 0 当结果返回到你的 if 条件时。