我有两个活动(ACT1和ACT2),并且都使用startActivityForResult(intent,0)调用另一个活动(ACT3)。我不太奇怪,因为ACT1在他的方法onActivityResult中正确接收了结果,但ACT2没有。在这种情况下,仅不会触发onActivityResult。 ¿是有原因的,还是错误?

提前致谢!

ps:添加的代码



public class ACT1 extends Activity
{
  .........


  @Override
  protected void onListItemClick(ListView l, View v, int position, long id)
  {
    ..........

    Intent intent = new Intent(this, ACT3.class);
    startActivityForResult(intent, 0);
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
    super.onActivityResult(requestCode, resultCode, data);

    Log.d(TAG, "ACT1: onActivityResult");

    this.finish();
  }
}




public class ACT2 extends Activity
{
.........


  @Override
  protected void onListItemClick(ListView l, View v, int position, long id)
  {
    ..........

    Intent intent = new Intent(this, ACT3.class);
    startActivityForResult(intent, 0);
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
    super.onActivityResult(requestCode, resultCode, data);

    Log.d(TAG, "ACT2: onActivityResult");

    this.finish();
  }
}




public class ACT3 extends Activity
{
.......


  @Override
  public void onClick(View v)
  {
    switch (v.getId())
    {
        case R.id.phaBtnAceptar:
            intent = new Intent();
            intent.putExtra("alarmTime", alarmTime);
            setResult(Activity.RESULT_OK, intent);

            finish();

            break;

        ........
    }
  }
}




这是设置警报的方法,该方法调用ACT2(AlarmaListaActivity)

private static void asignarAlarma(Context ctx, String idLista, String nombreLista, long horaInicioAlarma)
{
    String idAlarma = DAOMarket.getInstance().insertarAlarma(idLista, nombreLista, "" + horaInicioAlarma, "0");

    Intent intent = new Intent(ctx, ACT2.class);
    intent.putExtra("idLista", idLista);
    intent.putExtra("nombreLista", nombreLista);
    intent.putExtra("horaInicioAlarma", horaInicioAlarma);

    PendingIntent mAlarmSender = PendingIntent.getActivity(ctx, Integer.parseInt(idAlarma), intent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, horaInicioAlarma, mAlarmSender);
}

最佳答案

在act3中,尝试更改

intent = new Intent();




Intent intent = getIntent();

10-04 20:00