onCreate() method with if-else condition - android

I am calling an activity namely LoginActivity.java in which i am getting values using Intent, storing data to SQLite, fetching data from SQLite and given a small condition, condition looks like this:
if(txtEvent.getText().toString().equals("") && txtOperative.getText().toString().equals(""))
{
Intent intentCall = new Intent(LoginActivity.this, LicenseListActivity.class);
startActivity(intentCall);
}
Now, how App works:-
Splash Screen > LoginActivity (if txtEvent and txtOperative equals to null) then calling > LicenseListActivity > GetEventsActivity > GetOperativesActivity (passing some values mainly EVENT & OPERATIVE name) to LoginActivity (also storing to database - checked using SQLite DB Viewer)
So issue is, instead of calling LoginActivity.java its calling LicenseListActivity.java again, after GetOperativesActivity.java ?
GetOperativesActivity.java:-
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
firstName = contactList.get(position).get(TAG_NAME);
Intent intent = new Intent(GetOperativesActivity.this, LoginActivity.class);
intent.putExtra("name", name);
intent.putExtra("deviceID", deviceID);
intent.putExtra("emailID", emailID);
intent.putExtra("firstName", firstName);
startActivity(intent);
}
});
LoginActivity.java:-
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_login);
btnLogout = (Button) findViewById(R.id.btnLogout);
btnCamera = (Button) findViewById(R.id.btnCamera);
btnGallery = (Button) findViewById(R.id.btnGallery);
txtDeviceID = (TextView) findViewById(R.id.txtDeviceID);
txtEmailID = (TextView) findViewById(R.id.txtEmailID);
txtEvent = (TextView) findViewById(R.id.txtEvent);
txtOperative = (TextView) findViewById(R.id.txtOperative);
txtEventOperator = (TextView) findViewById(R.id.txtEventOperator);
Intent intent = getIntent();
deviceID = intent.getStringExtra("deviceID");
emailID = intent.getStringExtra("emailID");
event = intent.getStringExtra("name");
operative = intent.getStringExtra("firstName");
txtDeviceID.setText(deviceID);
txtEmailID.setText(emailID);
txtEvent.setText(event);
txtOperative.setText(operative);
txtEventOperator.setText(event + " " + operative);
strEvent = txtEvent.getText().toString();
strOperative = txtOperative.getText().toString();
// Dialog
final AlertDialog.Builder adb = new AlertDialog.Builder(this);
AlertDialog ad = adb.create();
// new Class DB
final myDBClass myDb = new myDBClass(this);
// Save Data
long saveStatus = myDb.InsertData(
txtDeviceID.getText().toString(),
txtEmailID.getText().toString(),
txtEvent.getText().toString(),
txtOperative.getText().toString(),
txtEventOperator.getText().toString()
);
if(saveStatus <= 0)
{
ad.setMessage("Error!! ");
ad.show();
return;
}
// Show Data
String arrData[] = myDb.SelectData();
if(arrData != null)
{
txtDeviceID.setText(arrData[1]);
txtEmailID.setText(arrData[2]);
txtEvent.setText(arrData[3]);
txtOperative.setText(arrData[4]);
txtEventOperator.setText(arrData[5]);
}
if(txtEvent.getText().toString().equals("") && txtOperative.getText().toString().equals(""))
{
Intent intentCall = new Intent(LoginActivity.this, LicenseListActivity.class);
startActivity(intentCall);
}
}
If you have any question in your mind, please let me know ...

public class LoginActivity extends Activity{
static int counter = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_login);
btnLogout = (Button) findViewById(R.id.btnLogout);
btnCamera = (Button) findViewById(R.id.btnCamera);
btnGallery = (Button) findViewById(R.id.btnGallery);
txtDeviceID = (TextView) findViewById(R.id.txtDeviceID);
txtEmailID = (TextView) findViewById(R.id.txtEmailID);
txtEvent = (TextView) findViewById(R.id.txtEvent);
txtOperative = (TextView) findViewById(R.id.txtOperative);
txtEventOperator = (TextView) findViewById(R.id.txtEventOperator);
Intent intent = getIntent();
deviceID = intent.getStringExtra("deviceID");
emailID = intent.getStringExtra("emailID");
event = intent.getStringExtra("name");
operative = intent.getStringExtra("firstName");
txtDeviceID.setText(deviceID);
txtEmailID.setText(emailID);
txtEvent.setText(event);
txtOperative.setText(operative);
txtEventOperator.setText(event + " " + operative);
strEvent = txtEvent.getText().toString();
strOperative = txtOperative.getText().toString();
// Dialog
final AlertDialog.Builder adb = new AlertDialog.Builder(this);
AlertDialog ad = adb.create();
// new Class DB
final myDBClass myDb = new myDBClass(this);
// Save Data
long saveStatus = myDb.InsertData(
txtDeviceID.getText().toString(),
txtEmailID.getText().toString(),
txtEvent.getText().toString(),
txtOperative.getText().toString(),
txtEventOperator.getText().toString()
);
if(saveStatus <= 0)
{
ad.setMessage("Error!! ");
ad.show();
return;
}
// Show Data
String arrData[] = myDb.SelectData();
if(arrData != null)
{
txtDeviceID.setText(arrData[1]);
txtEmailID.setText(arrData[2]);
txtEvent.setText(arrData[3]);
txtOperative.setText(arrData[4]);
txtEventOperator.setText(arrData[5]);
}
if(counter==0&&txtEvent.getText().toString().equals("") && txtOperative.getText().toString().equals(""))
{
counter++;
Intent intentCall = new Intent(LoginActivity.this, LicenseListActivity.class);
startActivity(intentCall);
}
}//end onCreate
}//end class

Related

Sending integers via Intent method

I have seen a decent amount of methods to add a numerical value to an int integer value using intent(). Mine however is not working so well. Does anyone have any advice? I am sending an integer value, via a button, from a separate activity using theintent() method. This value should add 1 to the activity when the button is pressed. Here is what I have so far:
public class GameEmulator extends Activity{
//Creating two static values to pass strings from SelectPlayer classes
public final static String value = "EMPTY_VALUE";
public final static String value2 = "EMPTY_VALUE2";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
//Button created to go back to AddPlayer activity
Button addplayer1 = findViewById(R.id.button9);
addplayer1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(GameEmulator.this, AddPlayer.class);
startActivity(i);
}
});
Button viewScores = findViewById(R.id.viewScore);
viewScores.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(GameEmulator.this, MainActivity.class);
startActivity(intent);
}
});
//Button for player one winning
Button winButtonOne = findViewById(R.id.button7);
winButtonOne.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int scored = 1;
Intent intent = new Intent(GameEmulator.this, Scoreboard.class);
intent.putExtra("MY_KEY", scored);
startActivity(intent);
}
});
TextView textView = findViewById(R.id.name1);
TextView textview2 = findViewById(R.id.name2);
//setting value retrieved from SleectPlayer and Displaying it in textView
Intent intent = getIntent();
String extra = intent.getStringExtra(value);
textView.setText(extra);
//setting value retrieved from SleectPlayer2 and Displaying it in textView2
Intent in = getIntent();
String extra1 = in.getStringExtra(value2);
textview2.setText(extra1);
}
}
public class Scoreboard extends Activity{
public static ArrayAdapter<String> adapter2;
public static ArrayAdapter<String> adapter3;
public static ArrayList<String> list2 = new ArrayList<>();
public static ArrayList<String> list3 = new ArrayList<>();
ListView selectView3;
ListView selectView4;
public static int losses1 = 0;
public static int ties1 = 0;
public static int losses2 = 0;
public static int ties2 = 0;
public final static String value2 = "EMPTY_VALUE2";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scoreboard);
selectView3 = findViewById(R.id.selectview3);
selectView3.setVisibility(View.VISIBLE);
selectView4 = findViewById(R.id.selectview4);
selectView4.setVisibility(View.VISIBLE);
//Using adapter for ListView menu
adapter2 = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list2);
selectView3.setAdapter(adapter2);
//Using intent to retrieve string from AddPlayer Activity
Intent i = getIntent();
int score = getIntent().getIntExtra("MY_KEY", 1);
String data = i.getStringExtra("text_key");
if(data != null){
list2.add("Player 1"+"\n"+"Name: "+data+"\n"+"Wins: "+ score +"\n"+"Losses: "+ losses1+"\n"+"Ties: "+ ties1);
}
if(data != ""){
changeList();
}
adapter3 = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list3);
selectView4.setAdapter(adapter3);
Intent intent = getIntent();
String extra= intent.getStringExtra(value2);
if(extra != null) {
list3.add("Player 2" + "\n" + "Name: " + extra + "\n" + "Wins: " + score + "\n" + "Losses: " + losses2 + "\n" + "Ties: " + ties2);
}
if(data != ""){
changeList();
}
}
public void changeList()
{
adapter2.notifyDataSetChanged();
}
}
This line:
String data = i.getStringExtra("text_key");
makes data = null because you did not put in the original intent an extra value with key "text_key"
So this code:
list2.add("Player 1"+"\n"+"Name: "+data+"\n"+"Wins: "+ score +"\n"+"Losses: "+ losses1+"\n"+"Ties: "+ ties1);
is never executed

My EditText keeps coming out as null

I've been working on this app that collects information, then sends it in email form. All of my other EditTexts are working with the exception of the very first one, pilot (the hint is name, as in the name of the pilot). I've gone through this thoroughly for multiple hours but I just cant seem to find what is the problem. The only reason I know its null is because when it goes into the email format all it says is null
public class InfoSheet extends AppCompatActivity {
private double VesselUnits;
private EditText pilot, ship, to, from, LOA, MBDTH, CUSD, zone1, zone2, CallSign;
private Spinner agent_spinner;
private Button btnSubmit;
private String date, agent, Spilot, Sship, Sto, Sfrom, Szone1, Szone2, SCallSign, SVesselUnits;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info_sheet);
date=getTodaysDate();
addListenerOnButton();
}
public void collectNCalc(){
//grab all of our info
agent_spinner = (Spinner) findViewById(R.id.agent_spinner);
btnSubmit = (Button) findViewById(R.id.btnSubmit);
pilot = (EditText) findViewById(R.id.Pilot);
ship = (EditText) findViewById(R.id.ship);
to = (EditText) findViewById(R.id.to);
from = (EditText) findViewById(R.id.from);
LOA = (EditText) findViewById(R.id.LOA);
MBDTH = (EditText) findViewById(R.id.MBDTH);
CUSD = (EditText) findViewById(R.id.CUSD);
zone1 = (EditText) findViewById(R.id.zone1);
zone2 = (EditText) findViewById(R.id.zone2);
CallSign = (EditText) findViewById(R.id.CallSign);
//convert what we need to int to do equations
String sLOA = LOA.getText().toString();
double intLOA = Integer.valueOf(sLOA);
intLOA = intLOA*3.281;
String sMBDTH = MBDTH.getText().toString();
double intMBDTH = Integer.valueOf(sMBDTH);
intMBDTH = intMBDTH*3.281;
String sCUSD = CUSD.getText().toString();
double intCUSD = Integer.valueOf(sCUSD);
intCUSD = intCUSD*3.281;
VesselUnits = intLOA*intMBDTH*intCUSD;
VesselUnits = VesselUnits/10000;
Spilot=pilot.getText().toString();
Sship=ship.getText().toString();
Sto=to.getText().toString();
Sfrom=from.getText().toString();
Szone1=zone1.getText().toString();
Szone2=zone2.getText().toString();
SCallSign=CallSign.getText().toString();
agent=agent_spinner.getSelectedItem().toString();
//SVesselUnits=String.valueOf(VesselUnits);
}
public void addListenerOnButton() {
final Context context2 = this;
btnSubmit = (Button) findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i2 = new Intent(context2, DigitalSignature.class);
//do the Calc
collectNCalc();
//pass to next activity
i2.putExtra("Pilot",Spilot);
i2.putExtra("ship",Sship);
i2.putExtra("to",Sto);
i2.putExtra("from",Sfrom);
i2.putExtra("zone1",Szone1);
i2.putExtra("zone2",Szone2);
i2.putExtra("callsign",SCallSign);
i2.putExtra("agent",agent);
i2.putExtra("vessleunits",VesselUnits);
i2.putExtra("date",date);
startActivity(i2);
}
});
}
its sent to the next and final activity:
public class DigitalSignature extends AppCompatActivity {
String pilot, ship, to, from, zone1, zone2, CallSign, agent, date;
Toolbar toolbar;
Button btn_get_sign, mClear, mGetSign, mCancel, btn_send;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_digital_signature);
Bundle extras = getIntent().getExtras();
if (extras != null) {
pilot = extras.getString("pilot");
ship = extras.getString("ship");
to = extras.getString("to");
from = extras.getString("from");
zone1 = extras.getString("zone1");
zone2 = extras.getString("zone2");
CallSign = extras.getString("callsign");
agent = extras.getString("agent");
vesselUnit = extras.getDouble("vesselunits");
date = extras.getString("date");
}
btn_send.setOnClickListener(new OnClickListener() {
public void onClick(View v){
Uri path = Uri.parse("file://" + file);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_TEXT, pilot+"\n"+ship+"\n"+to+"\n"+from+"\n"+zone1+"\n"+zone2+"\n"+CallSign+"\n"+agent+"\n"+vesselUnit);
// set the type to 'email'
emailIntent.setType("image/png");
String to[] = {"metropilottickets#gmail.com"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent.putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent.putExtra(Intent.EXTRA_SUBJECT, pilot+"'s Ticket for "+ship);
startActivity(Intent.createChooser(emailIntent , "Send email..."));
}
});
}
I left out a lot of the other code that's irrelevant to my question, but if anyone can point out why I'm getting null you'd be a life saver!
You need to use extras.getString("Pilot");
insteadof extras.getString("pilot");

TextView update not happening when selected item from ListView

Hi I have Listview in that when I select an item I display another page where I am setting the text views with appropriate informations but when i select an item and go back and select another item the textviews are not getting updated ?BTW there are 10 text views can somebody provide me the solution for this? Thanks.
super.onCreate(savedInstanceState);
setContentView(R.layout.lastl);
Intent i = getIntent();
ACK = i.getStringExtra("ack-no");
NAME = i.getExtras().getString("appl name");
TRADE = i.getExtras().getString("trade");
PIN = i.getExtras().getString("pin");
MOBILE = i.getExtras().getString("mobile");
EMAIL = i.getExtras().getString("email");
LVO1 = i.getExtras().getString("LVO1");
LVO2 = i.getExtras().getString("LVO2");
tv1 = (TextView) findViewById(R.id.set_ack);
tv1.setText(ACK);
tv2 = (TextView) findViewById(R.id.set_apl);
tv2.setText(NAME);
tv3 = (TextView) findViewById(R.id.set_trd);
tv3.setText(TRADE);
tv4 = (TextView) findViewById(R.id.set_dr);
tv4.setText(ArrayAdapter.ar.get(0));
tv5 = (TextView) findViewById(R.id.set_flr);
tv5.setText(ArrayAdapter.ar.get(1));
tv6 = (TextView) findViewById(R.id.set_bdg);
tv6.setText(ArrayAdapter.ar.get(2));
tv7 = (TextView) findViewById(R.id.set_str);
tv7.setText(ArrayAdapter.ar.get(3));
tv8 = (TextView) findViewById(R.id.set_area);
tv8.setText(ArrayAdapter.ar.get(4));
tv9 = (TextView) findViewById(R.id.set_dis);
//tv9.setText(ArrayAdapter.ar.get(5));
tv10 = (TextView) findViewById(R.id.set_pin);
tv10.setText(PIN);
tv11 = (TextView) findViewById(R.id.set_mb);
tv11.setText(MOBILE);
tv12 = (TextView) findViewById(R.id.set_email);
tv12.setText(EMAIL);
tv13 = (TextView) findViewById(R.id.set_pn);
tv14 = (TextView) findViewById(R.id.set_bdgg);
tv15 = (TextView) findViewById(R.id.set_dt);
tv16 = (TextView) findViewById(R.id.set_lvo);
tv16.setText(LVO1);
String lvo2 = LVO2.substring(0, LVO2.length() - 1);
Log.d("sssssss", lvo2);
tv17 = (TextView) findViewById(R.id.set_lvo2);
tv17.setText(lvo2);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(this);
b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
break;
case R.id.button2:
break;
}
}
this is my listView code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listmain);
pv = getIntent().getStringArrayListExtra("Array_list");
System.out.println("ARRAYLIST---->" + pv);
final ListView list = (ListView) findViewById(R.id.listView1);
mylistData = new ArrayList<HashMap<String, String>>();
String[] columnTags = new String[]{"col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8"};
int[] columnIds = new int[]{R.id.col1, R.id.col2, R.id.col3, R.id.col4, R.id.col5, R.id.col6, R.id.col7, R.id.col8};
int k = 0;
for (int i = 0; i <= 9; i++) {
HashMap<String, String> map = new HashMap<String, String>();
//initialize row data
for (int j = 0; j <= 7/*pv.size()-1*/; j++) {
map.put(columnTags[j], pv.get(k));
put(columnTags[j], "row" + i + "col" + j);
k++;
}
mylistData.add(map);
}
SimpleAdapter arrayAdapter = new SimpleAdapter(this, mylistData, R.layout.rowmain, columnTags, columnIds);
list.setAdapter(arrayAdapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parnet, android.view.View view, int position, long id) {
new LongOperation().execute();
String text = list.getItemAtPosition(position).toString();
String g = text.replace("{col5=", "");
String g1 = g.replace(" col4=", "");
String g2 = g1.replace(" col7=", "");
String g3 = g2.replace(" col6=", "");
String g4 = g3.replace(" col1=", "");
String g5 = g4.replace(" col3=", "");
String g6 = g5.replace(" col2=", "");
String g7 = g6.replace(" col8=", "");
String val[] = g7.split(",");
for (int m = 0; m < val.length; m++) {
Log.d("VALUE", val[m]);
ar1.add(val[m]);
}
System.out.println(ar1);
Log.d("VALUES-------->", text);
mob = ar1.get(0);
Log.d("VALUE1", mob);
pin = ar1.get(1);
Log.d("VALUE2", pin);
lvo = ar1.get(2);
Log.d("VALUE3", lvo);
email = ar1.get(3);
Log.d("VALUE4", email);
ack = ar1.get(4);
Log.d("VALUE5", ack);
trade = ar1.get(5);
Log.d("VALUE6", trade);
name = ar1.get(6);
Log.d("VALUE7", name);
lvo2 = ar1.get(7);
Log.d("VALUE8", lvo2);
}
});
}
From your code: ar1.add(val[m]);
I guess that ar1 is a List<String> variable of your listview activity?
If that's true, maybe add a call to clear() may work:
ar1.clear();
for(int m =0 ; m< val.length ; m++)
{
Log.d("VALUE",val[m]);
ar1.add(val[m]);
}

Android Application stopped suddenly

I'm preety new on android and trying to write an application but I wrote some code and run on android device till here there is no any problem but when I try to launch query window "sorgulama.xml" application stopped my xml file like this
and my java scource file ( java code ) like this
public class Sorgulama extends Activity implements OnClickListener {
#Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.btnSorgula:
String sorgu = txtSorgu.getText().toString();
Sorgula(sorgu);
break;
case R.id.btnKisaYollar:
KisaYollar();
break;
case R.id.btnTablo:
Tablolar();
break;
}
}
Button btnSorgula, btnKisaYollar, btnTablo;
EditText txtSorgu;
TableLayout tbl;
ResultSetMetaData metaData;
TableRow renkTableRow;
int kolonSayisi = 0, tvId = 0, otoId = 1;
String url,driver,userName ,password;
ArrayList<String> arrayTablolar = new ArrayList<String>();
ArrayList<String> arrayResults = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.sorgulama);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setTitle("MSSQL Uygulaması v1.0");
Kontroller();
Ayarlar();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);
}
private void Ayarlar()
{
DB db = new DB(this);
db.open();
Cursor c = db.Query();
String ipAdresi = null, veriTabaniAdi = null, kullaniciAdi = null, sifre = null;
while(c.moveToNext())
{
ipAdresi = c.getString(c.getColumnIndex("IpAdresi"));
veriTabaniAdi = c.getString(c.getColumnIndex("VeriTabaniAdi"));
kullaniciAdi = c.getString(c.getColumnIndex("KullaniciAdi"));
sifre = c.getString(c.getColumnIndex("Sifre"));
}
url = "jdbc:jtds:sqlserver://" + ipAdresi +";databaseName=" +veriTabaniAdi+"";
driver = "net.sourceforge.jtds.jtbc.Driver";
userName = kullaniciAdi;
password = sifre;
db.close();
}
private void Kontroller()
{
btnSorgula = (Button) findViewById(R.id.btnSorgula);
btnKisaYollar = (Button) findViewById(R.id.btnKisaYollar);
btnTablo = (Button) findViewById(R.id.btnTablo);
txtSorgu = (EditText) findViewById(R.id.txtSorgu);
tbl = (TableLayout) findViewById(R.id.tblSonuc);
btnSorgula.setOnClickListener(this);
btnKisaYollar.setOnClickListener(this);
btnTablo.setOnClickListener(this);
}
private void KisaYollar(){
final CharSequence cs[];
cs = new String[5];
cs[0] = "select";
cs[1] = "*";
cs[2] = "from";
cs[3] = "where";
cs[4] = "and";
cs[5] = "or";
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Kısa Yollar").setIcon(R.drawable.logo).setItems(cs, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
String sorgu = txtSorgu.getText().toString();
txtSorgu.setText(sorgu+cs[item]);
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void Tablolar(){
}
private void Sorgula(String sorgu)
{
}
}
Can anyone help me about this issue pls?
you missed super.onCreate(savedInstanceState). Also
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
must be called before setContentView

getIntent() not capturing data properly

I am passing row id with the help of intent. The calling method being a custom adapter -
holder.text.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "TEXT CLICKED" + pos , Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context,ReminderModificationActivity.class);
long longPos = (long)pos;
intent.putExtra(TasksDBAdapter.KEY_ROWID, pos);
Log.i(TAG, "row clickd --> " + longPos);
((Activity) context).startActivityForResult(intent, ACTIVITY_EDIT);
}
});
OnCreate() method of ReminderModificationActivity try to retrieve the data.Code -
protected void onCreate(Bundle savedInstanceState){
dbHelper = new TasksDBAdapter(this);
//set current theme
settingsDBAdapter = new SettingsDBAdapter(this);
settingsDBAdapter.open();
setSettingsTheme();
setContentView(R.layout.reminder_modify);
mCalendar = Calendar.getInstance();
Log.i(getLocalClassName(), "VALUE of Button--->" + findViewById(R.id.SetDateButtonId));
mDateButton = (Button) findViewById(R.id.SetDateButtonId);
mTimeButton = (Button) findViewById(R.id.SetTimeButtonId);
mConfirmButton = (Button) findViewById(R.id.SaveButtonId);
mTitleText = (EditText) findViewById(R.id.TitleEditTextId);
mBodyText = (EditText) findViewById(R.id.DescriptionEditTextId);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(TasksDBAdapter.KEY_ROWID) : null ;
registerButtonListenersAndSetDefaultText();
Log.i(TAG, "getIntent-->" + getIntent() + mRowId);
//code to check what row id have been passed
if(getIntent() != null) {
---->>>MAIN CODE
Log.i(TAG, "mRowId in getintent-->" + mRowId + "row id passed-->" + getIntent().getLongExtra(TasksDBAdapter.KEY_ROWID, -1));
mRowId = getIntent().getLongExtra(TasksDBAdapter.KEY_ROWID, -1);
// Do stuff with the row id here
if(mRowId != -1){
//code if RowId valid
}
}
super.onCreate(savedInstanceState);
Log.i(TAG, "mROwId in onCreate ReminderNotification again-->" + mRowId);
}
line marked as MAIN CODE captures the intent data but Log.i gives value of
getIntent().getLongExtra(TasksDBAdapter.KEY_ROWID, -1))
as -1.Can sumone please help me out on this.Thanks in advance,Ray
Seeing as you cast pos to longPos, you should be using longPos in your intent extra, but you use pos.
if you were to change your code to:
Intent intent = new Intent(context,ReminderModificationActivity.class);
long longPos = (long)pos;
intent.putExtra(TasksDBAdapter.KEY_ROWID, longPos); //<< changed to longPos
It should work

Categories

Resources