Delphi Seattle Android Service Development (i)

Source: Internet
Author: User

Starting with the Delphi support for Android, Android service development has always been the delphier of the past,

There have been methods to develop the service, but it is manual processing of the boot file, and to modify a lot of things, basically successful

The probability is very low.

Delphi Seattle (The name is very special, like WIN10, directly skipped 9) finally officially supported the Android service development,

Don't know if it's easy to develop Android service now? So let's explore.

First, we open the already flat no more flat Delphi 10, choose to build a different project. Appear:

Choose the first green robot (don't think, it's Android stuff) and click Confirm. Go to the next diagram:

Choose the type of service, different types of functionality is not the same, I will introduce later, today first choose First, from the simplest start.

After you click OK, a project is generated.

We change the project name to the name we like, and then we save it to a directory (remember, it is saved separately to a directory, and the main words are to say a few times?). )。

Notice the name. And then place a control
usesAndroidapi.JNI.App;functionTandroidservicedm.androidservicestartcommand (ConstSender:tobject; Constintent:jintent; Flags, Startid:integer): Integer;beginLthread:= Tthread.createanonymousthread (procedure    begin        whileTrue Do       beginSleep (10000);       Donotification; End; End); Lthread.freeonterminate:=False;   Lthread.start; Result:= TJService.JavaClass.START_STICKY;//Keep service runningEnd; proceduretandroidservicedm.donotification;varmynotification:tnotification;beginmynotification:=notificationcenter1.createnotification; TryMynotification.name:='xalion'; Mynotification.title:='time to go.'+formatdatetime ('YYYY-MM-DD hh:nn:sss', now); Mynotification.alertbody:='lazy people are going to get up.'; Mynotification.firedate:=Now ;  Notificationcenter1.presentnotification (mynotification); finallyMynotification.free; End;

OK, point Buider Project, certainly not run. Because he is a so, certainly can't afford to run.

Now we set up a standard main program, of course, FMX, if you want to build a VCL application, then I suggest you go to see a psychiatrist.

As I said before, be sure to save to another directory.

Window as follows

and enter the following code
typeTmainf=class(tform) Label1:tlabel;    Button1:tbutton;    Notificationcenter1:tnotificationcenter;    Memo1:tmemo; procedureButton1Click (Sender:tobject); procedurenotificationcenter1receivelocalnotification (sender:tobject;  Anotification:tnotification); Private    {Private Declarations}fservice:tlocalserviceconnection;  Public    {Public Declarations}  End;varMainf:tmainf;Implementation{$R *.FMX}procedureTmainf.button1click (sender:tobject);beginFservice:= Tlocalserviceconnection.Create; Fservice.startservice ('Xalionservice');End;proceduretmainf.notificationcenter1receivelocalnotification (sender:tobject; anotification:tnotification);beginTthread.queue (Nil,procedure  beginMemo1.  Lines.add (Anotification.alertbody); End);End;

Works as follows

Right-click on the top of the black body and select Add Android service.

The next window appears

Select the directory for the service app just now.

Just keep going.

When you're done, look at the project file

Then look at the release page to make sure that these two files exist correctly. What's left to do?  Of course it was compiled and run. Point to run the service. Exit the program, etc for 10 seconds "boom" "Boom" "ding" phone rang came out of the upper left corner of a flame icon.  Let's see what it is. The lazy people get up and click again and return to our main program.

This is the first service. Don't you think it's easy?

Anyway is basically tossing a day.

What phone is still called every 10 seconds, of course. Why, there is the truth of the code, see for yourself.

Can not stop, how to do, very simple, the application is deleted, it is not called:)

Today sacrificed a day of bragging time, finally finished this.

You can write something else later.

Delphi Seattle Android Service Development (i)

Related Article

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.