Make your own program into a jar package and let someone else call

Source: Internet
Author: User

When we write programs, we often need to package our own programs into jars.package, called to a third party. Eclipse makes it very convenient for us to export jarspackage. But it needs to be used in the program.Res, there are often problems with resources. Because the system automatically generatesRif the class is hitJarin the package, the role of the index resource is lost. resulting in encapsulation intoJarPackage ofViewunable to get the corresponding resource. BecauseRThe property values of the class are automatically assigned by the system when the app compiles the package. Rafter the class is packaged, it is actually becauseRThe properties inside the class are invalidated because the values of these properties are fixed after packaging, but the actual project values are automatically assigned at compile time and cannot be fixed before compilation. This article provides a way to solve this problem. First set up a Androidjar project. This project is going to be a jar in the future.the package item. The structure is as follows:
<ignore_js_op> then build a androidjartest project. This project is the application jarthe package item. When Androidjar is written, the jar is exported.package. I believe you are very familiar with the following steps:1. Select Androidjar, right-click the export. 2. Selectjar File. Just export the source code.
<ignore_js_op>
1. Then click Finish. You can export the jar package. Androidjartest How the project applies to jar packages. 1. Create a Libs folder under the Androidjartest project and put the jar package you just exported inside. Add the jar package to the path of the Java build path .
<ignore_js_op>
2. Because just now the source of the Androidjar into a jar package. But the resources are not packaged. So now it's time to put the resources in the Androidjar project. Copy to the Androidjartest project. Specifically , the file under Res. Because it is too simple, there is no way to show how to cuff.
2. Finally register the activity in the Androidjar in Androidjartest's androidmanifest.xml ,Service ,receiver. This is what many ad plugins do. I believe you are very familiar with it.
[Java]Plain Text view copy code ?
010203040506070809101112131415161718192021222324252627282930313233343536 <applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name" ><activityandroid:label="@string/app_name"android:name=".AndroidJarTestActivity" ><intent-filter ><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><!-- AndroidJar 里的activity,service和receiver--><activityandroid:name="com.song.test.FirstActivity"android:screenOrientation="portrait"android:theme="@android:style/Theme.NoTitleBar" ></activity><activityandroid:name="com.song.test.AndroidJarActivity"android:screenOrientation="portrait"android:theme="@android:style/Theme.NoTitleBar" ></activity><service android:name="com.song.test.service.HelloService" ></service><receiver android:name="com.song.test.receiver.ToastReceiver" ><intent-filter ><action android:name="MAKE_TOAST_ACTION" /></intent-filter></receiver><!-- AndroidJar 里的activity,service和receiver--></application>

in the androidjartest, just one other activity. It is responsible for jumping into the Androidjar. Androidjar in the three button is to start a service, every ten seconds issued a broadcast, and then broadcast received after the pop-up toast, "Hello, I am cang teacher!" "and a stop service. The bottom one is jumping to a teacher's interface.
<ignore_js_op><ignore_js_op><ignore_js_op> The program is fairly simple. It creates a view based on the resource , and the core class that finds the corresponding character according to the resource is Resmanager. We can download the source code, research and research.


<ignore_js_op> The post has been synced to Feathersong's Weibo
<ignore_js_op>

Make your own program into a jar package and let someone else call

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.