Value drop in getIntent ()

0

My problem is this ... I have a notification routine that the user clicks on the notification screen, open a new Activity. In this new Activity I show some information that I look for in the database depending on the code that I pass by parameters, however, I am not able to recover this code in the new Activity.

I'll put the classes to explain better:

This class below I call as soon as I insert the notification into the database:

public class AlarmUtilSessao {    

    // Agenda o alarme com repeat
    public static void scheduleRepeat(Context context, Intent intent, long triggerAtMillis, long intervalMillis, int id) {
        intent.putExtra("ID_SESSAO",id);
        PendingIntent p = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager alarme = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        alarme.setInexactRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis, p);
    }   
}

In my Manifest I call the receiving class the receiver:

<receiver android:name=".Lembretes.LembreteSessao">
            <intent-filter>
                <action android:name=".Alarm.Lembretes.LEMBRE_SESSAO" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </receiver>

My class that is triggered by the receiver is this one below. I correctly receive the ID and work with it in the database:

public class LembreteSessao extends BroadcastReceiver {
    private static final String TAG = "Sessao";
    public static final String ACTION = ".Alarm.Lembretes.LEMBRE_SESSAO";
    

    String currentTime, currentDate, newDate, newTime;
    int Ano, Mes, Dia, Hora, Minu;
    Date time, date;
    SimpleDateFormat timeFormat, dateFormat;
    JN_26_Alertas horarioModel;


    //CLASSE CHAMADA PELO MANIFEST NO HORARIO DO ALARME
    @Override
    public void onReceive(Context context, Intent intent) {
        ctx = context;
        codigo = intent.getIntExtra("ID_SESSAO", 0);

        Intent notifIntent = new Intent(context, lembrete_sessao.class);//alterar

        notifIntent.putExtra("ID_SESSAO",codigo);        
        NotificationUtil.create(context, 3, notifIntent, R.mipmap.ic_launcher, "Sessao", "Verifique a Sessao");

        //new Thread() {
          //  public void run() {
                //...Acessos e manipulações do banco de dados
        //    }
        //}.start();
        notifIntent.putExtra("TIME", currentTime);
    }

So far the system has received and correctly passed values by putExtra and getIntExtra, however, by clicking on the notification displayed on the mobile screen, the value arrives at the next empty screen:

public class lembrete_sessao extends ActionBarActivity implements View.OnClickListener,
        DialogInterface.OnClickListener{

    private TextView                    horaReceita;
    private int                         codigo, idRem = 0, qtd = 0;;
    private ListView                    lista;
    private JN_65_RemedioSessaoAdapter  remedioSessaoAdapter;
    private List<JN_25_RemedioSessao>   listRemSessao = null;
    private String                      msgSMS = null;
    private RadioButton                 Whats, Messenger, SMS, Nenhum;
    private String                      ConfiguracaoAlarme = null, Time = null;
    private ArrayList<Integer>          codArrayRemedio = new ArrayList<Integer>();
    private AlertDialog                 alertConfirmacao;
    private EditText                    foneSMS;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lembrete_sessao);
        codigo = 0;
        codigo              = getIntent().getIntExtra("ID_SESSAO", 0);
        Time                = getIntent().getStringExtra("TIME");
      
      //****

The variable TIME is also null, but it's not that important ... if I can get the value of the code I can retrieve the value TIME in the database ... any suggestions? Thank you in advance.

    
asked by anonymous 16.08.2016 / 17:48

1 answer

1

Try this:

Bundle extras = getIntent().getExtras();
if(extras == null) {
    id_sessao = null;
} else {
    id_sessao = extras.getString("ID_SESSAO");
}
    
16.08.2016 / 18:36