java - Android all variables are reset when SMS is sent -


hey i'm making app in need send text message every time send message app opens again , variables reset(i have tried implement system save variables still reset), still sends message. why doing this, , how can fix it; code

public void sendsms(string phono, string mes)     {         pendingintent pi = pendingintent.getactivity(this, 0,         new intent(this, mainactivity.class), 0);         smsmanager sm = smsmanager.getdefault();         sm.sendtextmessage(phono, null, mes, pi, null);     }          //button uses method   b = (button) findviewbyid(r.id.b);     b.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v)         {             phono = "personal phone number";             if (phono.length() > 0 && mes.length() > 0)                 sendsms(phono, mes);             }         }); 

you asking smsmanager relaunch app when sms sent.

from docs,

public void sendtextmessage (string destinationaddress, string scaddress, string text, pendingintent sentintent, pendingintent deliveryintent), 

the pi in code used sentintent, means when sms sent out of device, smsmanager automatically trigger intent.

if don't want sms manager relaunch app again after sms sent, send null in place of pi.

sm.sendtextmessage(phono, null, mes, null, null); 

Comments