In Android programming, there is a difference between the hardware return button and the back button on the navigation bar. My application has a view where, if I click the back button, the application will shut down. But, if I click the button on the navigation bar, it works great. There are various methods called based on two different types of buttons (e.g. oncreate vs onresume).
The class I call the back button:
public class ViewContact extends ActionBarActivity { Button btnDelete; TextView name; TextView position; TextView email; TextView phone; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_contact); getActionBar().setDisplayHomeAsUpEnabled(true); name = (TextView)findViewById(R.id.contactName); position = (TextView)findViewById(R.id.contactPosition); email = (TextView)findViewById(R.id.contactEmail); phone = (TextView)findViewById(R.id.contactPhone); btnDelete = (Button)findViewById(R.id.deleteContactBtn); Bundle takeBundledData = getIntent().getExtras(); final String contactName = takeBundledData.getString("clickedName"); String contactPosition = takeBundledData.getString("clickedPosition"); String contactEmail = takeBundledData.getString("clickedEmail"); String contactPhone = takeBundledData.getString("clickedPhone"); name.setText(contactName); position.setText(contactPosition); email.setText(contactEmail); phone.setText(contactPhone); btnDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MySQLiteHelper androidOpenDbHelper = new MySQLiteHelper(getApplicationContext()); SQLiteDatabase sqliteDatabase = androidOpenDbHelper.getWritableDatabase(); String[] whereClauseArgument = new String[1]; whereClauseArgument[0] = contactName;
Logcat Error:
java.lang.RuntimeException: Unable to resume activity: java.lang.IllegalStateException: trying to requery an already closed cursor android.database.sqlite.SQLiteCursor@43cfb6f0
Besides the error, although this is another problem, why this happens only with the hardware, and not with the back panel in the navigation panel.
source share