Run the Android program on a single instance. The Android program runs.

Source: Internet
Author: User

Run the Android program on a single instance. The Android program runs.

<?xmlxxxx?><manifestxxxxxxx>    <applicationandroid:icon="@drawable/icon"          android:label="@string/app_name"        android:launchMode="singleInstance">    <activityandroid:name=".Main"          android:label="Main Window"          android:icon="@drawable/icon>        <intent-filter>            <actionandroid:name="android.intent.action.MAIN"/>            <categoryandroid:name="android.intent.category.LAUNCHER"/>        </intent-filter>      <activityxxxxxxxxx/></manifest>


The fifth line of XML...


Android programming how to run the program in the background

It runs in the background using services of one of the four android components, similar to services on Windows.
1. There are two ways to start the service on Android (or two ways to implement the service)
① StartService () and bindService () are different.
2. Simple Steps for using Service (startService ()):
① Create a subclass of the service and override onStartCommand (). (This method is called when the service is started)
Public class HelloService extends Service {@ Override public void onCreate () {}// this function uses onStart () in earlier versions, and onStart () is outdated in later versions. @ Override public int onStartCommand (Intent intent, int flags, int startId) {}@ Override public void onDestroy () {}} ② declare the Service component in the configuration file
<Application> <service android: name = "HelloService"> <intent-fiter> <action android: name = "xxxxx"> </intent-fiter> </service> </application> ③ call startService (intent) in Activity; Start your Service
Intent intent = new Intent ("xxxxx"); // you can also use Intent intent = new Intent (activity. this, HelloService. class); startService (intent); note: the two methods are different. For details, see the official API:
Developer.android.com/guide/components/services.html


How does android make the app run in the background like QQ?

Data in json format can be put into an http request, and a unique user ID can be added to the json data of the request.

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.