Completely new to this and to Android development, looking for a bit of help if possible. I am developing my first application for Android at the moment and have very little coding experience...I basically have an application at the moment that is allowing me to add/delete/update users to and from a sqlite database. I am looking for a way just to add a button on the main homepage that allows me to access the camera and take a picture. The main activity is simply a page with buttons to add/delete etc:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
DatabaseHelper mDatabaseHelper;
private Button btnAdd, btnViewData;
private EditText editText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
btnAdd = (Button) findViewById(R.id.btnAdd);
btnViewData = (Button) findViewById(R.id.btnView);
mDatabaseHelper = new DatabaseHelper(this);
btnAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String newEntry = editText.getText().toString();
if (editText.length() != 0) {
AddData(newEntry);
editText.setText("");
} else {
toastMessage("Please enter a name!");
}
}
});
btnViewData.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ListDataActivity.class);
startActivity(intent);
}
});
}
public void AddData(String newEntry) {
boolean insertData = mDatabaseHelper.addData(newEntry);
if (insertData) {
toastMessage("User Added!");
} else {
toastMessage("Something went wrong");
}
}
/**
* customizable toast
* #param message
*/
private void toastMessage(String message){
Toast.makeText(this,message, Toast.LENGTH_SHORT).show();
}
}
The code I have for implementing the camera is shown below(it works for invoking the camera and taking a picture but only from the camera outside the application)
Is it possible for me to just a button on the main activity page that allows me to "take picture" from within the application
(code for invoking camera)
public class MainActivity extends AppCompatActivity {
public void getPhoto() {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults.length > 0 && grantResults[0] == PackageManager. PERMISSION_GRANTED){
getPhoto();
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
} else{
getPhoto();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
try {
Uri selectedImage = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Sorry if the question seems stupid, completely new to Android development and new to coding so I am very unsure.
I'm not sure about what you are looking for, but here is code to take a picture :
https://developer.android.com/training/camera/photobasics.html
To add the button, you need to add it in the layout then get the reference in your activity class with the findViewById method
Hope this help
Related
I am new to Android and programming as a whole and I need a little help with callbacks. I understand the gist of callbacks but I am unsure of how to go about implementing.
Context: I am writing a simple notetaking app that allows the user to write text and saving it to the app. The user can then request to read the file with a button. The text is then displayed on a textview in the main activity. There is an option to wipe this file and this is done with a confirmation pop up, which is another activity. This pop up contains 2 buttons, one to cancel and one to wipe. If the file is not empty it will wipe and does nothing if empty. I am not sure if this is the best way to implement it but I want to use the wipe button to callback to the main activity to clear the textview. The way I was thinking of was by using the callback to send a boolean value back. The main activity will check if the boolean is true and clear the textview if it is. I am unsure of how to implement the callback in my popup display to send this boolean value back to the main activity.
Code for main activity
public class MainActivity extends AppCompatActivity implements Popout.ClearTextView {
Button bnRead,bnWrite,bnClear;
TextView tvFileOP;
EditText etInput;
// private static final String INPUT_CONTENT = "inputContent";
public static final String TV_CONTENT = "textViewContent";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bnRead = (Button) findViewById(R.id.bnRead);
bnWrite = (Button) findViewById(R.id.bnWrite);
bnClear = (Button) findViewById(R.id.bnClear);
tvFileOP = (TextView) findViewById(R.id.tvFileOP);
etInput = (EditText) findViewById(R.id.etInput);
tvFileOP.setMovementMethod(new ScrollingMovementMethod());
final String fileName = "test_file";
String data;
bnRead.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
FileInputStream fIn = openFileInput(fileName);
int c;
String temp = "";
while ( (c=fIn.read()) != -1){
temp = temp + Character.toString((char) c);
}
tvFileOP.setText(temp);
Toast.makeText(getBaseContext(),"file successfully read", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
bnWrite.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String data = etInput.getText().toString();
try {
FileOutputStream fOut = openFileOutput(fileName,MODE_APPEND);
fOut.write(data.getBytes());
fOut.close();
etInput.setText("");
Toast.makeText(getBaseContext(),"file successfully written", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
bnClear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,Popout.class));
}
});
}
#Override
protected void onSaveInstanceState(#NonNull Bundle outState) {
outState.putString(TV_CONTENT,tvFileOP.getText().toString());
super.onSaveInstanceState(outState);
}
#Override
protected void onRestoreInstanceState(#NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
tvFileOP.setText(savedInstanceState.getString(TV_CONTENT));
}
#Override
public void clearTextView(Boolean clear) {
if (clear){
tvFileOP.setText("");
}
}
}
Code for popup confirmation menu
public class Popout extends AppCompatActivity {
Button bnClosepopup,bnWipe;
TextView tvConfirmation;
String fileName = "test_file";
TextView tvFileOP;
public interface ClearTextView {
public void clearTextView(Boolean clear);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popupwindow);
bnClosepopup = (Button) findViewById(R.id.bnClosepopup);
bnWipe = (Button) findViewById(R.id.bnWipe);
tvConfirmation = (TextView) findViewById(R.id.tvConfirmation);
//HIDING THE TOOL BAR AT THE TOP OF THE SCREEN
this.getSupportActionBar().hide();
//GETTING THE SIZE OF THE SCREEN
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
getWindow().setLayout((int) (width*0.8) , (int) (0.8*height));
bnClosepopup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
bnWipe.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
File dir = getFilesDir();
File file = new File(dir, fileName);
boolean deleted = file.delete();
Toast.makeText(getBaseContext(),"file has been deleted",Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
finish();
}
});
}
}
I am very new to android development and any tips on how to improve my code would be greatly appreciated :)
In this case there is no way to pass the interface to the other activity, because this is an activity to activity communication.
You have to use some other method, there is multiple ways to approach, the best way I can think of is to use startActivityForResult() to start the activity and then wait for a response to come back, and then query this response in the MainActivity by overriding the onActivityResult() method:
Example
In the MainActivity:
//on click of this button
bnClear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,Popout.class);
int requestCode = 12; //it could be whatever you want
startActivityForResult(intent , requestCode);
}
});
//override this method
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//this is triggered when you finish the Popout Activity
if(requestCode == 12 && resultCode == Activity.RESULT_OK){
// get the boolean data returned from the Popout Activity
boolean deleted = data.getBooleanExtra("deleted_state" , false); //false is default if no value exists
}
}
In the Popout activity:
bnWipe.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
File dir = getFilesDir();
File file = new File(dir, fileName);
boolean deleted = file.delete();
//send the result to onActivtyResult() in MainActivity
Intent result = new Intent();
result.putExtra("deleted_state", deleted );
setResult(Activity.RESULT_OK, result);
Toast.makeText(getBaseContext(),"file has been deleted",Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
finish();
}
});
UPDATE:
It will be like this:
// get the boolean data returned from the Popout Activity
boolean deleted = data.getBooleanExtra("deleted_state" , false);
if (deleted){
tvFileOP.setText("");
}
..........
As far as what if Understood your problem correctly: You want to control your 'Wipe' button click event from your activity. Here is the solution which may help you.
1: Make an overridden constructor of your dialog class.
2: Create one abstract method in the dialog class. (say - onWipeButtonClick)
You need to make your dialog class abstract as well.
3: Inside on Click Listener of 'Wipe' button, call onWipeButtonClick abstract method.
4: Create the instance of dialog in the main activity where ever you want. The compiler will give you an error because you haven't implemented the call back method.
do implement your onWipeButtonClick method and do needful for wipe data inside the method.
public abstract class WipeDialog extends Dialog{
private Context context;
public WipeDialog(Context context){
this.context = context;
}
public abstract void onWipeButtonClick(boolean isTextEmpty);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.<XML_FILE>);
<initialization>
btnWipe.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onWipeButtonClick(<YOUR_BOOLEAN_CHECK>);
}
});
}
}
And now in Activity:
WipeDialog dialog = new WipeDialog(MainActivity.this) {
#Override
public void onWipeButtonClick(boolean isTextEmpty) {
//Do Need full with respected to your requirement on click of button 'WIPE'
}
};
Hope this will help.
Thanks!
I am stuck trying to figure out where exactly to put the finish() function in my code.
I have tried putting it on line 43 of ProfileActivity or lines 39 or 56 of MainActivity. I'm very new at this and have read what the purpose of finish() is but can't figure out where else in my code it should go.
These are just nippets of the code ... there is more (all the Activity lifecycle functions), but I omitted to save space.
public class MainActivity extends AppCompatActivity {
SharedPreferences sp;
EditText email;
public static final String ACTIVITY_NAME = "PROFILE_ACTIVITY";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
email = (EditText)findViewById(R.id.thisEmailIsPassedToPage2);
sp = getSharedPreferences("Lab3", Context.MODE_PRIVATE);
String savedString = sp.getString("Email", "0");
email.setText(savedString);
Log.e(ACTIVITY_NAME, "In Function onCreate() in MainActivity:");
Button login = (Button)findViewById(R.id.loginButton);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,
ProfileActivity.class);
EditText et =
(EditText)findViewById(R.id.thisEmailIsPassedToPage2);
intent.putExtra("typed", et.getText().toString());
startActivityForResult(intent, 2);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
int i = 0;
i++;
//if request code is 2, then we are coming back from ProfileActivity
if(requestCode == 2){
EditText et =
(EditText)findViewById(R.id.thisEmailIsPassedToPage2);
String fromProfile = data.getStringExtra("typed");
et.setText(fromProfile);
Log.i("Back", "Message");
}
}
public class ProfileActivity extends AppCompatActivity {
private SharedPreferences sp;
private ImageButton mImageButton;
public static final String ACTIVITY_NAME = "PROFILE_ACTIVITY";
public static final int REQUEST_IMAGE_CAPTURE = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profileactivity);
Log.e(ACTIVITY_NAME, "In Function onCreate() in ProfileActivity:");
Intent fromPrevious = getIntent();
String previousTyped = fromPrevious.getStringExtra("typed");
EditText enterText = (EditText) findViewById(R.id.editText6);
enterText.setText(previousTyped);
mImageButton = (ImageButton) this.findViewById(R.id.imageButton);
mImageButton.setOnClickListener(bt -> {
dispatchTakePictureIntent();
});
}
private void dispatchTakePictureIntent(){
Intent takePictureIntent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageButton.setImageBitmap(imageBitmap);
}
}
These are the screenshots:
[MainActivity1stPage][1]
[ProfileActivity2ndPage][2]
[AfterImageButtonPressed][3]
[AfterTakingPictureAndPressingOK][4]
If I'm getting it right, your flow is MainActivity starts ProfileActivity for result, then in ProfileActivity you start the ACTION_IMAGE_CAPTUREfor result, so I'm guessing that with that result you want to trigger your MainActivity onActivityResult. So if that the case you need to setResult and finish at the onActivityResultof your ProfileActivity.
I am attempting to create a list of users in an android app. The list is on the MainActivity, with a button which redirects to AddMember. AddMember will take input for one member. I am trying to pass the information back to MainActivity, however it fails before I even get to the AddMemberActivity, when testing. It stops after the button click on the MainActivity.
Trie implementation
The error message is:
java.lang.NullPointerException: Attempt to invoke virtual method 'char java.lang.String.charAt(int)' on a null object reference
at attendance.Trie.get(Trie.java:117)
at attendance.Trie.get(Trie.java:113)
at attendance.MainActivity$1.onClick(MainActivity.java:49)
line 49 is
if (trie.get(name) != null) {
public class MainActivity extends AppCompatActivity {
private Button button;
private ListView list;
private Trie trie;
private ArrayAdapter<String> adapter;
private int count = 0;
private static final int REQUEST_CODE = 100;
private String name;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_CODE) {
if(resultCode == RESULT_OK) {
name = data.getStringExtra("name");
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.addBtn);
list = (ListView) findViewById(R.id.memberList);
trie = new Trie();
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), AddMember.class);
startActivityForResult(intent, REQUEST_CODE);
adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.content_list_items,R.id.list_content, trie.traverse());
list.setAdapter(adapter);
//check that member was added
if (trie.get(name) != null) {
// <- look for item!
//made an alert to show member already exists
} else {
trie.put(name.toLowerCase(), count++);
adapter.add(name);
}
adapter.notifyDataSetChanged();
}
});
}
}
public class AddMember extends AppCompatActivity {
//Array of options --> ArrayAdapter --> ListView
//ListView :{views, items.xml}
private static final int REQUEST_CODE = 100;
private Button button;
private EditText name;
private EditText phone;
private EditText email;
private ArrayAdapter<Member> adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_member);
button = (Button) findViewById(R.id.uploadMember);
name = (EditText) findViewById(R.id.edit_name);
//add member button
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("name", name.getText());
setResult(RESULT_OK, intent);
finish();
}
});
}
}
It is clear from crash log that you are attempting to get character from null string .
java.lang.String.charAt(int)' on a null object reference at attendance.Trie.get(Trie.java:117)
Reason : You are passing null value in get method. You never assign the name string and by default it is assigned with null. And you pass it with trie.get(name).
Check your get method of Trie class and put a check of null. If name is not null then get the character from string otherwise return null.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_CODE) {
if(resultCode == RESULT_OK) {
name = data.getStringExtra("name");
if(adapter == null){
adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.content_list_items,R.id.list_content, trie.traverse());
list.setAdapter(adapter);
}
//check that member was added
if (trie.get(name) != null) {
// <- look for item!
//made an alert to show member already exists
} else {
trie.put(name.toLowerCase(), count++);
adapter.add(name);
}
adapter.notifyDataSetChanged();
}
}
}
Remove adapter code from onClick method
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), AddMember.class);
startActivityForResult(intent, REQUEST_CODE);
});
What's wrong with my code? I sucessfully take the image, but the second activity is not starting. I want to pass my taken image to the second activity.
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private Button buttonka;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonka = (Button) findViewById(R.id.button);
{
buttonka.setOnClickListener(new View.OnClickListener() {
public void onClick (View v){
switch (v.getId()) {
case R.id.button:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
break;
}
}
});
}}
protected void onActivityResult(int requestCode, int resultCode, Intent data, Uri mCapturedImageURI) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap bitmapImage = (Bitmap) getIntent().getExtras().get("data");
Intent camintent = new Intent(MainActivity.this, Main2Activity.class);
camintent.putExtra("bitmap", bitmapImage);
startActivity(camintent);
}
}
}
Receiver activity:
public class Main2Activity extends AppCompatActivity {
private ImageView image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
getData();
}
private void getData() {
Bitmap bitImage = getIntent().getParcelableExtra("bitmap");
image.setImageBitmap(bitImage);
}
}
Somehow the application is not reacting, and not starting the second activity, may I missed something? Hope someone can help, thanks!
In your onActivityResult- use data.getExtras().get("data"), not getIntent. You don't want the intent used to launch the app, you want the one returned as a result.
I founded the solution, forget to add the camera and write storage permission in the manifest files. If anyone get in a problem like this, make sure you writing the correct permissions! :) + removed the unused Uri mCapturedImageURI)
Well I've run into an issue in my inventory app. I'm trying to retrieve a list of inventory items from Parse. This isn't the hardest thing in the world to do. At this point, I'm at a loss as to why the data is coming back as empty, when I can clearly see in Parse.com that there is data in the class I have requested from. Any ideas? (NOTE: I am able to add items to the database without a problem... it's just in the retrieval).
MainActivity:
public class MainActivity extends AppCompatActivity {
private ImageView mAddButton;
private ImageView mBackButton;
private Inventory mInventory;
private RecyclerView mRecyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAddButton = (ImageView) findViewById(R.id.addItemButton);
mBackButton = (ImageView) findViewById(R.id.backButton);
mBackButton.setVisibility(View.INVISIBLE);
mInventory = new Inventory();
ParseUser user = ParseUser.getCurrentUser();
if (user == null) {
navToLogin();
} else {
Toast.makeText(MainActivity.this, "Welcome!", Toast.LENGTH_SHORT).show();
getInventoryFromParse();
Toast.makeText(MainActivity.this, mInventory.toString(), Toast.LENGTH_LONG).show();
}
mAddButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addItem();
}
});
}
private void updateView() {
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
InventoryListAdapter adapter = new InventoryListAdapter(this, mInventory.getItemList());
mRecyclerView.setAdapter(adapter);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
}
private void addItem() {
Intent intent = new Intent(MainActivity.this, AddItemActivity.class);
startActivityForResult(intent, 1);
}
private void navToLogin() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case (1):
updateView();
}
}
}
public void getInventoryFromParse() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Item");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
mInventory.setItemList(objects);
} else {
Toast.makeText(MainActivity.this, "There was an error.", Toast.LENGTH_LONG).show();
}
}
});
}
}
The Inventory Class:
public class Inventory {
private List<ParseObject> mItemList;
public Inventory() {
mItemList = new ArrayList<>();
}
public List<ParseObject> getItemList() {
return mItemList;
}
public void setItemList(List<ParseObject> itemList) {
mItemList = itemList;
}
public void addItem(ParseObject item) {
mItemList.add(item);
}
#Override
public String toString() {
return "Inventory{" +
"mItemList=" + mItemList +
'}';
}
}
The query creates a new thread which runs in the background, then your main thread moves on, exits the function, and the query still hasn't completed when you go to print out the inventory. setInventory has not been called when the main thread prints mInventory to string.
That's why your code isn't working.
As for a solution, I'm not sure how the Android dev kit works, but my suggestion to keep your code split up the way it is would be to make getInventoryFromParse have a return type, and call return inside of the query callback. I'm not sure if that'll throw errors since the main thread reaches the end of the function... If that doesn't work, you'll have to rewrite your code so that anything that needs to happen after the items are fetched happens inside of the callback.