i am struck with passing String array from one activity to another using intent. while passing only a String from two activities, its work clear. but whenever i tried to access string array i am getting force close error. can any one guide me to rectify the problem.
You can use just the Intent.setExtra(String, Serializable) method. It accepts any Serializable object. If that does not work, please attach results from your LogCat, "Closed unexpectedly" just means your app failed, LogCat tells why it failed.
use Parcelable to do this.
please refer to this link http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/
Related
Intent.putExtra Error
I have no idea whats happening in my program.
I've tried parcelable, serializable, CharSequence & String.valueOf to avoid the error but it crash when I debuging run this line every time.
I check out most tutorial using same method but no error founded, What is the problem and how can I fix this.
Thank you.
object can't be put in extras directly it have to serialize then pass to intend
you can use this
https://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/
I have the following line of code
intent.putExtra("connectionAddress", connectionManager.connectionAddress);
connectionAddress is in fact an InetAddress. I cannot figure out the appropriate method to 'get..' this. I suspect I need to cast it to another type and back again? In which case what would be the best approach?
I need to ensure I still have the information needed to create a DatagramSocket in the next activity.
You need to get the address from the intent as a serializable extra, then cast it back to InetAddress.
InetAddress address = (InetAddress)intent.getSerializableExtra("connectionAddress");
I want to sent value to another activity. I'm using VS 2012 C# for developing apps. I have done lot of search from google. I have tried almost every methods. in my application getIntent(); giving error. that is, getIntent() does not exist in the current context.
I'm also not getting these below functions in my application.
Intent sender=getIntent();
getApplicationContext();
I have added all references. Help me where Am I wrong?
I got answer, I have to use below line of for getting value:
string extraData = Intent.GetStringExtra("KeyName");
Following statement is not executing on some devices.
AddEvent act1 = (AddEvent) getLocalActivityManager().getCurrentActivity();
Is there any alternate method for above statement. On some devices it works fine but on other devices it gives exception.
Edit: My application is developed in tab. OnActivity results is used for getting picture from camera activity. Dont know where the resides but when I puts the above statement in try catch then no force close occurs and exception is shown there.
The problem is not really with the casting, but the assumption that the Object returned by getLocalActivityManager().getCurrentActivity() is of type AddEvent. It would be difficult to say in what scenario does the getLocalActivityManager().getCurrentActivity() return an Object that is of not the AddEvent type without looking at your implementation.
The following piece of code will check if the returned Object is indeed of type AddEvent:
if(getLocalActivityManager().getCurrentActivity() instanceof AddEvent){
AddEvent act1 = (AddEvent) getLocalActivityManager().getCurrentActivity();
}
But in your case, it is recommended to check in what scenario does the getLocalActivityManager().getCurrentActivity() return an instance of fable.eventippo.Home as against fable.eventippo.AddEvent.
I am not sure where do you write this line but logcat output says: You are trying to cast Home Activity into AddEvent and this is why its giving you ClassCastException.
FYI, getLocalActivityManager().getCurrentActivity(); is returning Home.
I am trying to send bean object(implents Serializable) with 16 strings data obtained from a parser. I am sending that using putExtra("string",serializablevalue) and I'm receiving that using getIntent().getSerializable("string"). I have used this option for almost 10 functionalities it works fine for me.But particular this functionality alone always returns me null in receiving location.I have cross checked it while sending.it has value. While in the receiving location.
My doubt will bean with 16 fields could be sent with this method. Suggest me a better solution for this problem.
Try:
getIntent().getExtras().getSerializable("string")
My code works fine with ArrayList<String>. Could you please give me/us your serializable-strings?
On the other side, based on this: http://developer.android.com/reference/android/os/Parcelable.html, then if you use custom class, you need to "transfer" the data between: public void writeToParcel(Parcel out, int flags) and private MyParcelable(Parcel in).
In details, you can write your data to out, and get them from in.
Check if the String are equals to in both activities!!
it happened to me I had one different capital letter, when I corrected it it worked :)