Converting string to object

Is it possible to convert a string that was created by Object.ToString() back to the original object i.e:

            public boolean dispatchKeyEvent (KeyEvent event) {     
                return super.dispatchKeyEvent(event);      

appent log will log every keyevent as a string in a new line. After logging i would like to run the logged keyevents

Is it possible to convert the string logged keyevents to a KeyEvent object?


Only if the toString() contains all the necessary event information. If it's just a hash code, of course not. If the relevant info is available, you'd need to parse it, and use one of the KeyEvent constructors, and hope there's nothing internally that isn't reflected in the toString. Seems sketchy to me.

If you need to store it, it's Parcelable, that might help.

You still have the event in the snippet you show, without an actual usecase it's hard to know what you're trying to do.

In general, no. The String won't contain enough information to reconstruct the original object. Of course, if you do encode enough information in the String returned by toString(), you may reconstruct the object - for instance, you can serialize an object to an XML - a String, and from that XML rebuild the object that originated it. Take a look at JAXB.

Need Your Help

How to receive and use a json in ajax sended from php?

php json

I want to receive json from php to ajax and want to access the different field values in json.

Updatepanel gives full postback instead of asyncpostback

c# ajax updatepanel postback

I have run into what seems to be a very famous problem: My updatepanel fires a full postback instead of a async postback. The normal solution is to give all controls you add dynamically an ID, whic...

How can I switch a text box for a <label>, <div>, or <span> using jQuery? javascript jquery html

I'm trying to "single source" a form page which can be in edit mode or view mode. For various reasons, this isn't using the ASP.Net FormView or DetailsView controls.