I have 2 tables : book and user ,now I need to make another table but it should get some fields from book and some from user ,separately I can ,but when I go to another fragment to get other fields from book table the username ,which I save it to a string, returns null
08-04 10:47:27.319 4004-4004/com.example.pars.amanatdari I/bookName: args : Bundle[{status=null, userName=jack, bookName=null}]
08-04 10:47:30.139 4004-4004/com.example.pars.amanatdari I/bookName: args : Bundle[{status=available, userName=null, bookName=نون والقلم}]
what should I do exactly?I dont know even what to search
send data from fragment :
Bundle args = getArguments();
String username = args.getString("userName");
and get data :
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String bookName = bundle.getString("bookName");
String bookStatus = bundle.getString("status");
String bookUser = bundle.getString("userName");
borrowFragment borrowFragment = new borrowFragment();
Bundle args2 = new Bundle();
args2.putString("bookName", bookName);
args2.putString("status", bookStatus);
args2.putString("userName", bookUser);
Log.i("bookName", "args : " + args2);
borrowFragment.setArguments(args2);
getSupportFragmentManager().beginTransaction().add(R.id.frg_container, borrowFragment, "tag").commit();
That is bound to happen , since the bundle gets null or overwritten after your visit to the book fragment .So what can be done is you can get the values from user fragment and pass the value to book fragment and then take both the values and go to the next fragment . You have to carry the data with you all the while
Related
I created one app like email clients app such as Gmail.
When user click on email address in another apps and choose my app from email sending apps in list appear on .
The email content like email address , email subject and .... come to my app by intent .
But the problem is intent.getData(); is null value all of the time and i try to get email data from intent .
I tested bundle in intent and i saw its not null and when i write this code :
bundle = intent.getExtras();
Log.e("Email",bundle.toString());
the bundle.toString() return Bundle[{android.intent.extra.EMAIL=[Ljava.lang.String;#11cda76c}] .
I dont know what is this [Ljava.lang.String;#11cda76c}] and how i can get the email address from here ! ?
Found answer here Passing values through bundle and get its value on another activity
bundle = this.getIntent().getExtras();
String email= bundle.getString("EMAIL");
Edit:
bundle = this.getIntent().getExtras();
String [] emails=bundle.getStringArray(Intent.EXTRA_EMAIL );
I'm creating an map that shows a result from a Parse query. I can pass information directly into the marker, such as a title or a lat/long, but I would like to include some additional information (not to be displayed) that I can use when the user clicks on the marker.
For instance when the user clicks on the marker, I would like to find the user's objectId from the Parse query (which is simply a string).
I've tried the following code in the marker onClickListener to put the string in as an argument:
destPosition = marker.getPosition();
destLat = destPosition.latitude;
destLong = destPosition.longitude;
MarkerDialogFragment markerDialogFragment = new MarkerDialogFragment();
Bundle args = new Bundle();
args.putString("id", marker.getId());
args.putString("userId", userId);
args.putString("title", marker.getTitle());
args.putDouble("latitude", destLat);
args.putDouble("longitude", destLong);
markerDialogFragment.setArguments(args);
when I try to extract this data on the "other side" by getting the arguments, the userId always comes across as null...I've defined userId as such:
final String userId = parseUsers.get(i).getObjectId();
I've even tried hard coding the string in userId as such, and it still comes back as null when I try to get the arguments:
final String userId = "test userId";
Here is the get arguments code for the marker onCreateDialog method:
builder = new AlertDialog.Builder(getActivity());
final String markerId = getArguments().getString("id");
final String userId = getArguments().getString("userId");
final String title = getArguments().getString("title");
final double destLat = getArguments().getDouble("latitude");
final double destLong = getArguments().getDouble("longitude");
builder.setTitle(title)
When I use the debugger to stop the code to see the values, all data is set as expected and I have values for each item EXCEPT the userId. Can anyone help point me in the right direction? I simply want to pass a value associated with a variable and have it be tied to each marker created on the map. Thanks!
You cannot add anymore data to the marker.
So if you want to add more data to your marker, you will have to store it in an external variable with marker's ID (getID())
eg -
HashMap<int,Object> extramarkerData = new HashMap<int,Object>();
and put data into hashmap
extramarkerData.put(marker.getId(),"additional data");
Good evening guys,
I'm making an app and I want to know how to send a string to "List-View" in another activity ?
You can send data using the following code -
Intent intent = new Intent(this,newActivity);
intent.putExtra(name, value)
name = The name of the extra data
value = The String data value.
startActivity(intent);
In the new activity, you receive string via following (in onCreate)
Intent intent = getIntent();
String str = intent.getString(name)
name = The name of the extra data
Now search the web on how to add a string to list view. You will find it easily
I'm trying to pass in two separate pieces of information to a new activity in my Android application.
I currently have this:
Bundle dataBundle = new Bundle();
Bundle extras = getIntent().getExtras(); // student id
dataBundle.putInt("id", 0);// lesson id
Intent intent = new Intent(getApplicationContext(),com.example.ltss.dyslexia.app.LessonNotes.class);
intent.putExtras(dataBundle);
intent.putExtras(extras);
startActivity(intent);
I then have the code accessing this information. However, adding the second bundle overrides the first one.
Bundle extras = getIntent().getExtras();
Bundle studentId = getIntent().getExtras();
Log.d("LessonID: ", String.valueOf(extras));
Log.d("StudentID: ", String.valueOf(studentId));
I need to have the information passed in separately as I need to check if one of them is null.
Can what i'm asking be done? Any ideas as to how to do this? Or another way to do this? (parsing maybe?)
Thanks
you could use putExtra("bundle1", bundle1) and putExtra("bundle2", bundle2) and then use getIntent().getBundleExtra("bundle1"); and getIntent().getBundleExtra("bundle2"); to retrieve both
Maybe you're over thinking this. You can put a ton of information in 1 bundle.
Bundle bundle = new Bundle();
bundle.putString("studentid", "Student0983");
bundle.putInt("lessonid", 0);
bundle.putString("moreinfo", "needed some extra data on that student");
bundle.putInt("studentincome", 4250);
Intent intent = new Intent(getApplicationContext(),com.example.ltss.dyslexia.app.LessonNotes.class);
intent.putExtras(bundle);
startActivity(intent);
Now to get that data in the new activity
Bundle bundle = getIntent().getExtras();
Log.d("studentid: ", bundle.getString("studentid"));
Log.d("lessonid: ", bundle.getInt("lessonid"));
Log.d("moreinfo: ", bundle.getString("moreinfo"));
Log.d("studentincome: ", bundle.getInt("studentincome"));
Thanks in advance.
When I print Log.d("me",getIntent().toString());
I am getting:
Intent { act=android.intent.action.CALL_PRIVILEGED dat=tel:888 flg=0x13800000 cmp=com.ninetology.freecall.two/.CallFinalActivity }
I am trying to fetch the value which is associated with "dat" but I am getting NullPointer exception.
//the code I am using is
getIntent().getStringExtra("dat"); // no use
//i tried
getIntent().getExtras("dat").toString(); // NullPointer exception
I tried with "tel" as key in above code still no use.
it seems you're doing this wrong.
The getExtras() function returns a bundle that you can extract data from and not a function that returns a specific String.
dat is NOT a String value as you can see from the data that was printed. it's a Uri,
try parsing it as you should and I'm sure you'll be able to get the data.
public void onCreate(Bundle b) { //mistyped
super.onCreate(b);
Uri data = getIntent().getData();
// OR USE THIS
String data = getIntent().getDataString();
// DO STUFF
}
try getIntent().getExtras().get("dat");
First of all, Its not necessary the string from Intent your are getting in log have a object with values..
So its better to just check its not a null, like,
Bundle bundle = getIntent().getExtras();
if(bundle ! = null)
{
// Now check you bundle object which has a values or not
}
else
{
// 1. get data in form of Uri
Uri data = getIntent().getData();
// 2. OR get string of Uri
String dataString = getIntent().getDataString();
// 3. Or split the data string
// The logic from this part may be different on your requirement.. I only suggests you to get data from string.. (Actual logic may different on your case)
String data = getIntent().toString();
data = data.subString(data.indexOf(":"), data.indexOf("flg")-1);
Log.e("tel:", data);
}
When you want to pass the data with the intent just add the below code before starting activity
intent.putExtra("dat", value); //value=the value you want to send
And when you want to fetch the same value in another activity just do:
Bundle bundle=getIntent().getExtras();
if(bundle!=null){
String string=bundle.getString("dat");
}
By doing this, you wont get the null pointer exception and will help you.