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

Pretty form validation

javascript jquery forms validation

I am currently validating my forms using an alert system from jquery. Just with this following code:

Session or Cookie

php session cookies

I've created a "Recently Viewed Items" script that utilizes sessions to insert viewed products into a database. Then, If there is a session it will pull the products you have viewed.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.