0

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 ...

Sun
  • 6,768
  • 25
  • 76
  • 131
  • from your GetOperativesActivity are you creating a new instance of Login Activity or clearing your back stack ? – Gaurav Mar 01 '14 at 09:46
  • calling LoginActivity.java using Intent, wait placing GetOperativesActivity code – Sun Mar 01 '14 at 09:51
  • can you post your android manifest as well? – Orhan Obut Mar 01 '14 at 09:58
  • are you sure your values are passed correctly to LoginActivity, have you placed a break point and confirmed you recieve proper values in these variables event, operative etc. – Gaurav Mar 01 '14 at 09:58
  • once i will remove that condition i will be able to call LoginActivity.java, but not able to enter into app, so condition requires – Sun Mar 01 '14 at 10:00
  • I think `LoginActivity` is called and then `LicenseListActivity` is called immediately. That's why you don't notice. `LoginActivity` is passed through – mangusta Mar 01 '14 at 10:19
  • seems that this condition `if(txtEvent.getText().toString().equals("") && txtOperative.getText().toString().equals(""))` is true. hence `LicenseListActivity` is called – mangusta Mar 01 '14 at 10:22
  • here i am asking same thing how to handle this situation @mangusta – Sun Mar 01 '14 at 10:26
  • @Moon first thing coming to mind, you may keep a static counter in `LoginActivity` to count each time the activity is called. if counter is >0 then ignore that condition. and reset when necessary – mangusta Mar 01 '14 at 10:28
  • can you show me the way ? how – Sun Mar 01 '14 at 10:32
  • see reply below. but it assumes that you need to call `LicenseListActivity` only once. if you need to call it later from `LoginActivity`, you may reset counter back to zero somewhere. – mangusta Mar 01 '14 at 10:36
  • not really accurate way of doing what you need, just first thing that comes to mind in order to quickly solve the problem – mangusta Mar 01 '14 at 10:39
  • tried but issue not resolved, can we control on first put values to text then check for condition, exist or not ? – Sun Mar 01 '14 at 10:45
  • @Moon what do you mean "not resolved" ? O_o it still calls `LicenseListActivity` after `GetOperativesActivity` ? – mangusta Mar 01 '14 at 10:48
  • no now its calling LoginActivity.java , but not showing values for TextViews, but showing values in Log – Sun Mar 01 '14 at 10:49
  • @Moon then I guess you should debug your `contactList` values and `myDb.SelectData()` logic – mangusta Mar 01 '14 at 10:53
  • check log report here: http://pastebin.com/WqiS3dnY @mangusta – Sun Mar 01 '14 at 10:54

1 Answers1

1
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
mangusta
  • 3,470
  • 5
  • 24
  • 47
  • thank you so much, yes you were right, i removed the fetch data from SQLite code and now its showing values in TextViews, can you explain why you used counter in LoginActivity ? – Sun Mar 01 '14 at 11:14
  • in order to check this condition `if(txtEvent.getText().toString().equals("") && txtOperative.getText().toString().equals(""))` first time when `LoginActivity` is called. when it is called afterwards, counter will be 1 and condition will be ignored. – mangusta Mar 01 '14 at 11:16
  • ok, when i relaunch my app after closing it properly my mean from TaskList as well, not getting LoginActivity, where it has data in TextVIews, so it should call LoginActivity, not LicenseListActivity – Sun Mar 01 '14 at 11:18
  • when you relaunch your app, counter will be 0, but `if(txtEvent.getText().toString().equals("") && txtOperative.getText().toString().equals(""))` will be false, i guess :) so you will not call `LicenseListActivity` and will stay in `LoginActivity` – mangusta Mar 01 '14 at 11:22
  • so what you would recommend me to achieve that ? – Sun Mar 01 '14 at 11:23
  • I didn't get what you exactly want. Do you want to stay in LoginActivity when txtEvent and txtOperative is null, or not? – mangusta Mar 01 '14 at 11:25
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48763/discussion-between-moon-and-mangusta) – Sun Mar 01 '14 at 11:26
  • now i got the reason, after using counter why i did not get values in textviews because it's inserting first row as blank and i was retreiving value of first row, now tell me how do i control on inserting blank rows into my database – Sun Mar 01 '14 at 11:57