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.