简体   繁体   中英

Android App switching activities

I've been working on my first true Android app for a few weeks, and I've been running into a bit of a problem. My app utilizing the Eclipse with the Android ADK can connect to a database that I have on a site, but when it tries to move towards the next activity it doesn't work. What is the problem?

Login.Java snippet:

   success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                Log.d("Login Successful!", json.toString());
                Intent n = new Intent(Login.this, ReadComments.class);
                finish();
                startActivity(n);
                return json.getString(TAG_MESSAGE);

ReadComments.class snippet:

public class ReadComments extends Activity{

 @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.read_comments);
}




@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add("Register")
    .setIntent(new Intent(this,Register.class));
menu.add("New Reservation")
    .setIntent(new Intent(this, NewReservation.class));
menu.add("About Luxury Parking")
.setIntent(new Intent(this, Aboutus.class));
return true;


}

}

You are calling finish() before you call startActivity(n) ; Calling finish() will destroy the activity, hence the other activity not starting. Also don't forget to declare it within your manifest file.

Probably the reason is manifest xml file changes.

Here is a sample, enter this under application tag ;

<activity android:name="mete.gcm.info" android:theme="@style/AppTheme"></activity>      

mete.gcm is my folder name (under src folder) info is my activity name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM