Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMUZ140698 Kudakwashe Gwaindepi
4,150 Pointsusing tabs and fragments
hey guys, im stuck please help
im using android studion 1.2 and when i first created my MainActivity i made it a blank activity, and now at this stage the video is talking about fragments and stuff. but my activity did not autogenerate the code generated on ben's.
how do i edit it to make my activity have tabs at this stage, your help is greatly appreciated.
here is the code of my MainActivity.java
package com.muzinda.kgwaindepi.ribbit;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseObject;
import com.parse.ParseUser;
public class MainActivity extends FragmentActivity {
public static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpened(getIntent());
ParseUser currentUser = ParseUser.getCurrentUser();
if(currentUser == null) {
navigateToLogin();
}
else {
Log.i(TAG, currentUser.getUsername());
}
ParseObject object;
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Parse.initialize(this, "jTxlNT63Iov1xTzImCOQiuAKfxDsVcjvbkPHwWvZ", "v7kKmfk2z23HWnVN2MGWsLovokYzLeHOK9vx09bD");
}
private void navigateToLogin() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int itemId = item.getItemId();
//noinspection SimplifiableIfStatement
if (itemId == R.id.action_logout) {
ParseUser.logOut();
navigateToLogin();
}
return super.onOptionsItemSelected(item);
}
}
1 Answer
Harry James
14,780 PointsHey there!
Sorry about my late reply - I've been extremely busy with exams recently.
You have probably managed to fix this by now but if not (Or if there's anyone else who needs the code), I have made it available from here.
Note that I'm not sure if this is exactly how it is in the video (It likely isn't) so if there's anything you don't understand, feel free to give me a shout :)