This is probably a very basic question but I couldn't find the answer.
I need to pass data from RecyclerView but when I check it on related activity, data is null.
mvHolder.barcode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent s = new Intent(context, SummaryActivity.class);
s.putExtra("SUMMARY",sp.getDATA().get(i).getId_summary()); // data is not null
context.startActivity(s);
}
});
and this is how I try to achieve it :
Bundle extras = getIntent().getExtras();
if (extras != null) {
strBarcode = extras.getString("SUMMARY");
// and get whatever type user account id is
}
but when I debug it, it turns out that strBarcode is null. I don't know what the problem is, I guess my code should be works either. Please help me
Intent data = getIntent();
if (data != null) {
strBarcode = data.getStringExtra("SUMMARY");
// and get whatever type user account id is
}
Intent data = getIntent();
if (data != null) {
int strBarcode = data.getIntExtra("SUMMARY");
}
Please try this
Check if getIntent().hasExtra("SUMMARY") returns true.
If it does, make sure that sp.getDATA().get(i).getId_summary() returns a String.
The extra might be there, but you try to get as String, and it might
have different type.
Related
I have an activity called GatherActivity where I have an EditText. The user can input what ever he wants. Now I need the input of that EditText in a different class, called MapActivity.
I created an Intent to "put it over" in the other activity. But it doesn't work like I aspect it. the object/editText is allways a null object, so nothing is displayed as a markerSnippet.
Here my Code (GahterActivity) in a method onButtonClick():
public void onButtonClick(View view){
EditText editText_markerSnippet = (EditText) findViewById(R.id.editText_markerSnippet);
Intent intent = new Intent(this, MapActivity.class);
intent.putExtra("markerSnippet", editText_markerSnippet.getText().toString());
}
Code in MapActivity:
Bundle extras = getIntent().getExtras();
if(extras != null){
markerSnippet = extras.getParcelable("markerSnippet");
}else{
markerSnippet = "some extra info about your location"
}
in my marker snippet there is no text. so the else case is not in use here...
You're sending a String, but expecting a Parcelable in your activity.
In your MapActivity, change it to:
markerSnippet = extras.getString("markerSnippet");
I tried to send string from onclick recyclerview to the activity, all doing well except one of this.
GeneralItem generalItem = (GeneralItem) consolidatedList.get(position);
Intent intent = new Intent(getActivity(), DetailPengumuman.class);
intent.putExtra("getnama", generalItem.getDaftarPengumuman().getNama_p().toString());
Log.e("untaging","ada isinya : "+generalItem.getDaftarPengumuman().getNama_p().toString());
intent.putExtra("tanggalpengumuman", generalItem.getDaftarPengumuman().getTanggal_peng());
intent.putExtra("judulpengumuman", generalItem.getDaftarPengumuman().getJudul());
intent.putExtra("deskripsipengumuman", generalItem.getDaftarPengumuman().getDeskripsi());
startActivity(intent);
I also tried to log getnama in untaging tag its doing well and return me the data in log. But when I retrieve it in another activity, It always return null.
Intent intent = getIntent();
tanggalPengumumanGet = intent.getStringExtra("tanggalpengumuman");
judulPengumumanGet = intent.getStringExtra("judulpengumuman");
namaPengumumanGet = intent.getStringExtra("getnama");
deskripsiPengumumanGet = intent.getStringExtra("deskripsipengumuman");
Log.e("untaging","nama : " +namaMatkulGet);
You can first check for if intent contains data or not..
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
if (bundle.containsKey("Key")) {
String value = bundle.getString("Key");
}
}
Trying Adding .toString() to call getStringExtra :
intent.putExtra("tanggalpengumuman", generalItem.getDaftarPengumuman().getTanggal_peng().toString());
intent.putExtra("judulpengumuman", generalItem.getDaftarPengumuman().getJudul().toString());
intent.putExtra("deskripsipengumuman", generalItem.getDaftarPengumuman().getDeskripsi().toString);
Solved thanks,
This because of I missing the String attribute
Intent intent = getIntent();
tanggalPengumumanGet = intent.getStringExtra("tanggalpengumuman");
judulPengumumanGet = intent.getStringExtra("judulpengumuman");
namaPengumumanGet = intent.getStringExtra("getnama");
deskripsiPengumumanGet = intent.getStringExtra("deskripsipengumuman");
Log.e("untaging","nama : " +namaMatkulGet);
I receiving extra in namaPengumumanGet and I log another String which is namaMatkkulGet
I am working on an android app whose main purpose is to update the working location of the employees by admin. Now when I want to change/update the location of an employee from my recycler view(list of employees connected with my UserManagerAdapter), I have to pass the user name of that employee to the place picker intent so that when the admin pick the desired location, the database of that user will be changed accordingly.
My Steps(2 Steps)
I have passed the username to the place picker intent as bundle.
My UserManagerAdapter
holder.locationTv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
launchPicker(data.get(position).getUserName());
}
});
private void launchPicker(String userName) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Bundle bundle = new Bundle();
bundle.putString(USERNAME,userName);
try {
fragment.startActivityForResult(builder.build(fragment.getActivity()),PLACE_PICKER_REQUEST,bundle);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
I received the location request inside of a fragment and update the location of that particular user
My ManageUserFragment
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PLACE_PICKER_REQUEST){
if(resultCode == RESULT_OK){
Place place = PlacePicker.getPlace(getContext(),data);
address = place.getAddress().toString();
String latLng = place.getLatLng().toString();
latLang = latLng;
//update user's decided location
Bundle bundle = data.getExtras();
String userName = bundle.getString(USERNAME);// it returns null, Why?
updateLocation(latLang,userName);
Toast.makeText(getContext(), latLng, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), getContext().getText(R.string.locationError), Toast.LENGTH_SHORT).show();
}
}
}
My constant is
public static final String USERNAME="Username";
Now,
My problem is
Why bundle.getString(USERNAME) always return null?
How to pass data to place picker intent so that we can receive it in
onActivityResult ?
After replicating your case and researching for a little bit, I found out that the third parameter in startActivityForResult() is not used to pass a bundle of values to the onActivityResult, it's used to pass options to Android itself, you can find those here. So if you want to pass any data you have to use an intent with putExtra("USERNAME", username), and you can retrieve it with getStringExtra("USERNAME"). It's explained in this answer as well.
so I store some basic data using parse in one activity, but how do I retrieve that data from parse(query it) in another activity? Can someone give me a clean cut example?
So in my main activity I have
public String max = "max";
Parse.enableLocalDatastore(this);
private ParseObject rightCardsStore = new ParseObject("RightCardsStore");
rightCardsStore.put("max",max);
rightCardsStore.saveInBackground();
Now, in another activity, "Folder.java" I want to query/retrieve that data and use that string.
As hitch.united said, you need to get the ID by doing a saveInBackground and send it to the other activity:
rightCardsStore.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Intent intent = new Intent(YourCurrentActivity.this, YourNewActivity.class);
intent.putExtra("parseObjectId", rightCardsStore.getObjectId());
YourCurrentActivity.this.startActivity(intent);
}
}
});
Then you can retrieve the data in your other activity, and query parse:
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String id = bundle.getString("parseObjectId");
ParseQuery<ParseObject> query = ParseQuery.getQuery("RightCardsStore");
query.getInBackground(id, new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object is the RightCardsStore you just saved
String max = object.getString("max");
}
}
}
}
If you just need to use max as a readonly value you can simplify the process by replacing (in the first activity)
intent.putExtra("parseObjectId", rightCardsStore.getObjectId());
by
intent.putExtra("max", max);
and replacing the second activity by:
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String max = bundle.getString("max");
}
After the saveInBackground get the ID of the object and pass it with an intent to the new activity. You can then requery with that ID to retrieve the object.
When a user shares an image to my app from another app, I want to receive it as an image and handle it.
I've already set up filters like this:
Now what I don't understand is how to actually receive the intent in my app nor how I could extract/handle an image from it.
I've tried googling the problem but no one seems to give a concrete answer on how to handle/receive the intent after setting up the filter.
I appreciate the help!
You can get the image uri in the activity like this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (type.startsWith("image/")) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
// Do whatever you want here
}
}
}
}
You can check the link for other mime types Handle the Incoming Content