views:

39

answers:

1

Hello,

I am new to android. I have a loginActivity which validates a user number and then starts a "searchactivity".

At runtime, I see the search activity coming up (after user is validated) but then android is having problems stopping the loginActivity.

I am getting a "java.lang.runtimeexception: Unable to stop activity {com.insruance/com.insurance.LoginActivity}: android.app.SuperNotCalledException : Activity at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3413)"

I would really appreciate if someone could point to what I am doing wrong.

Code :

public class LoginActivity extends Activity{

 DatabaseWrapper myDbHelper;
 private String agentNumber;
 private OnClickListener btnClickListner = new OnClickListener() 
 {  
  @Override
  public void onClick(View v) 
  {
   // TODO Auto-generated method stub   
   // = new DataBaseHelper();   
   try {

    Log.d("LoginActivity->onClick", "Before findByID");
    EditText editText = (EditText)findViewById(R.id.txtUserNumber);
    Log.d("LoginActivity->onClick", "After findByID");
    agentNumber = editText.getText().toString();
    String msg = "";
    AgentDbHelper agentHelper = new AgentDbHelper(myDbHelper.getDatabaseHandle());
    Log.d("LoginActivity->onClick", "Before agentIDExists");    
    if (agentHelper.agentIDExists(agentNumber))
     msg = "Login success";
    else
     msg = "Login failed";
    Log.d("LoginActivity->onClick", "After agentByID");
    myDbHelper.closeDatabase();
    myDbHelper = null;
    Toast.makeText(getBaseContext(), 
      "User " + agentNumber + " found!", 
      Toast.LENGTH_LONG).show();
    callSearchActivity();
   } 
   catch(SQLException sqlEx)
   {
    Log.d("login - onclick", sqlEx.toString());
   }
   catch (Exception e) {
    // TODO: handle exception
    Log.d("login - onclick", e.toString());
   } 
  }
 }; 

 private void callSearchActivity()
 {
  Intent intent = new Intent(getBaseContext(), SearchActivity.class);
  Bundle bun = new Bundle();
  bun.putString("agentNumber", agentNumber);
  intent.putExtras(bun);
  startActivity(intent);  
 }

 @Override
 public void onStop() {  
  try {
   Log.d("In LoginActivity->onStop", "about to close myDbHelper");
   if (myDbHelper != null)
   {
    myDbHelper.closeDatabase();
    Log.d("In LoginActivity->onStop", "after myDbHelper is closed");
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   Log.d("In LoginActivity->onStop exeption", e.toString());
   //e.printStackTrace();
  }
 }
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {        
         setContentView(R.layout.login);
         Button loginButton = (Button)this.findViewById(R.id.btnLogin);
         loginButton.setOnClickListener(btnClickListner);
         myDbHelper = new DatabaseWrapper(this);
         myDbHelper.openDatabase();
        }
        catch(Exception e) {
      Log.e("ERROR", "ERROR IN CODE:"+e.toString());
     }

} }

+1  A: 

A little more digging pointed me to this.

I was not calling super.onStop() within the overriden onStop.

I would have thought that Eclipse would have scripted this line when it created the onStop for me.

CF_Maintainer
Eclipse can't warn you about not calling super methods, it's Android's requirement and it's not coded in the plugin.
ognian
Its a VS hangover, expecting the IDE to do a lot. Getting used to Eclipse now.
CF_Maintainer