Android's Intent Method for passing Java objects, androidintent
In Android, Intent provides two methods to pass Java objects: one is to call the putSerializable (Key, Object) method of the Bundle Object 【See examples], The other is by calling the putParcelable (Key, Object) method of the Bundle Object 【See examples].
The first method requires that the passed Java object implement the Serializable interface -- the Serializable interface is a special interface of JavaSE. It is very easy to imple
serialization interface, such as Parcelable or Serializable. For example, we need to pass a user object to the user's personal information display page. Our general practice is as follows:
User. java class:
// Implement serialization of the object class public class User implements Parcelable {String name; String phoneNum; // other fields omit public User (String aName) {name = aName ;} public User (Parcel
Android | unmarshalling unknown type while using parcelable data in bundlesArraylist // Fill arraylist with a few model-objects
Bundle mbundle = new bundle;Intent mintent = new intent (aaaa. This, BBBB. Class );
Mbundle. putparcelablearraylist ("models", mmodellist );Mintent. putextras (mbundle );
Startactivity (mintent );Bundle mbundle = getintent (). getextras ();Arraylist Error/androidruntime (11109): Fatal exception: MainJava. lang. runtimeexcepti
1. Using BundlesThe activity, service, and receiver in Android support the delivery of bundle data in Intent, and the bundle implements the Parcelable interface, which can be conveniently transferred between different processes. When we start the Activity, Service, and Receiver of another process in one process, we can attach to the Bundle the information that needs to be transferred to the remote process and send it through Intent. Note: Transmitted
objects (serializable,parcelable)!
Intent Filter about action, category attributes-with instance source code
Startactivityforresult Usage Explanation
Android Development Notes-passing class objects via Intent
Jjson
Android Series-json Data parsing
Android JSON parsing and simple examples
Android Open Source Library –gson Google official JSON parsing library
Llistfragment
listfragment-descriptions and ex
Messenger (Mhandler); @Override public void OnCreate () {super.oncreate (); LOG.D (TAG, "onCreate:"); } @Nullable @Override public ibinder onbind (Intent Intent) {return messenger.getbinder (); }}Implement the service's Onbind () method, call ' Messenger.getbinder () ' To return a ibinder, return the IBinder we will receive and use on the client. Creates a handler that receives a message that is delivered by the client, and then sends a message to the client when the message is rec
above is the general basic data types, when the need to pass objects, you can enable the object to implement Parcelable or Serializable interface;
Add the object to the bundle through the bundle.putparcelable (key,obj) and Bundle.putserializable (Key,obj) methods, and then add the bundle object to the intent!
In the target page of the jump through Intent.getparcelableextra (Key) to achieve the Parcelable
management system, this system through the CS mode to achieve. The specific management function is implemented by the server-side process, and the client only needs to invoke the appropriate interface.
Then first define the ADIL interface for this management system.
We created a new Aidl package in/RC, with three files Book.java, Book.aidl, ibookmanager.aidl three files in the package.
Package Com.example.aidl Book Public
class book implements pa
DL files, such as beauty.aidl, add a sentence of pracelable Beauty inside.
Second: Start writing beauty, here must note that it must implement the Pracelable interface, which is a serialized interface, the function and serializable similar, but the function is more rapid. In addition, be sure to declare a public static final Pracelable.creator
Third: Register the service in the Androidmanifest.xml. and define the action string to access the service.
Client:The client side of the correspondin
(Maidlinterface.getvalue ());
catch (RemoteException e) {e.printstacktrace ();
}
}
}); } @Override protected void OnDestroy () {if (maidlinterface!= null) {UnbindseRvice (mserviceconnection);
} Super.ondestroy ();
}
}
Note that the incoming parameter string for the new intent here is a custom action tag inside manifest, and in OnDestroy Remember to unbind the service.
The result is that we will display the get value string returned by the server to us when we click TextView
Custom O
Http://www.pocketdigi.com/20121129/952.htmlBy default, Aidl supports objects as arguments, but requires the object to implement the Parcelable interface, and the Aidl file should be the same class under the same package, and you need to define a Aidl file for that class separately.To define a model class:Englishitem.java:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636
Android.os.Parcelable interface needs to be imported.The data types passed by the following programs are the person class, and the server code is as follows:(1) New person implementation Parcelable interfacepublic class person implements parcelable{private String name;private int age;public static final parcelable.creatorThe person implements the Android.os.Parcelable interface, which is used to serialize
activity.
ArrayList
Receive in another activity
2. Use the parcelable MethodAndroid memory is limited, forcing it to encapsulate the parcel container to replace the serializable method.Some comments are made in the code, so I will not explain them here.
/*** Parcel class: http://developer.android.com/reference/android/ OS /Parcel.html
A custom class, which is described in the comments and read the code.
//use Pa
What should I pay attention to when uploading objects to an activity in android?
I implemented the Parcelable interface through serializable, because it was relatively lazy and I didn't want to implement the Parcelable interface.
1. Modify the Class. Because Serializable is passed, inherit implements Serializable after the class.
2. Pass the value
Intent. putExtra (sid, scart );
You can use putExtra di
Intent (); intent. putExtra ("id", 1001); intent. setComponent (componentName); startActivity (intent );
After running the above Code, you will see that 1001 is printed in LogCat, indicating that the Intent sent from the AndroidTest process is normal.
Note: In the code above, we pass the basic data type. for basic data types, such as Int and String, you can directly read the data as above, however, if a complex object is sent, the object must implement the Serializable or
();} catch (JSONException e) {Log. e ("JSONException", e. getMessage ();} mBase64 = null; return jsonObj. toString (). getBytes () ;}/ *** describes the types of special objects contained in the Parcelable Object arrangement information. ** @ Return indicates the arrangement of special object types of Parcelable objects. */@ Override public int describeContents () {return 0 ;}/ *** constructor. ** @ Param
Document directory
How does Android call the system's default browser for access?
Today, you need to add a shortcut to the desktop so that you can link to a specific webpage when you click it. I found this article online.
Http://www.moandroid.com /? P = 1699
It was inspired to implement this function.
/*
* Add shortcuts to the desktop
* @ Param icon shortcut icon
* @ Param name shortcut name
* @ Param Uri the intent URI of the shortcut
*/
PublicVoidAddshortcut (
This article is translated from: Building instrumented unit TestsLevel limited oneself feel many places express not in place, but can't find the better expression way, if you think have better expression way, help me to improve!
Building instrumented Unit TestsThe instrumented unit test runs on your physical device or emulator, not the JVM in your local machine. If you need to get instrumentation information (such as the context of the target app) or you need an Android framework component
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.