Xamrin developing Android Notes (ii)

Source: Internet
Author: User

    • Installation article
    • Xamrin Developing Android Notes (i)

Yesterday conditioning a day AAPT.EXE was launched the problem (error code MSB6006: "Aapt.exe" exited with code-1073741819), Tangled day in the end is what reason, sleepless, later figured out may be the cause of Android simulator. This morning replaced an Android SDK, and now there is no AAPT error.

And you can visualize the layout (the previous visual layout is ugly). Then continue to write, temporarily discard vs2015, because 2015 of the bug directly affect my writing feeling, so first with vs2013 Update4 continued to write.

The first solution is the real machine debugging problems, did not have to do Android, do not know so debugging, in fact, super simple. Plug in the Android machine, the developer mode of the USB debugging options to open, find what kind of mobile phone butler and other things, the driver installed (some phone models do not automatically install the driver, resulting in the ability to recognize that he is a mobile device but can not let vs know Him, so it is best to find a housekeeper and other things to install the driver).

The first thing to write is to jump the value of things, this belongs to the common function. The layout is not much to say, is a button, dragged in to change a name. Change the ID, generate (in order to avoid the CS file can not find this ID, this thing is not said later)

1Btnto.click + =Delegate2             {3                 //the address to jump to4                 varSecond =NewIntent ( This,typeof(secondactivity));5                 //parameters with Past (Key,value)6Second. PutExtra ("Tel", txtphone.text);7                //Execute Jump8 startactivity (second);9};

Jump to another page with parameters. Another page gets the parameters

1 intent.getstringextra ("tel");

Data is checked by key. I feel the jump is simple.

Next I'll tell you about the notification event, there are several implementations of the notification event, but after I've finished, vs tells me that the method used is obsolete. It makes me very sad.

First of all, the general notice, Android's notice can be flashing lights, noise, vibration. These are implemented by notification properties.

The notification invokes the Notification class to implement. Take a look at the specific code

1Btnpush.click + =Delegate {2Notification notify =NewNotification (Resource.Drawable.Icon,"you have a new short message.");
Sound, vibration, led flashing need to call this property3Notify. Defaults =Notificationdefaults.all;4 //Note Ringtonemanager This needs to refer to Android.media; get system sound5Android.Net.Uri Uri =Ringtonemanager.getdefaulturi (ringtonetype.notification);6Notify. sound = URI;//Ringtone Path7 //Vibration Mode array form, {vibration time, interval time, vibration time}8Notify. Vibrate =New Long[] { +, -, +};9 //the color static class needs to refer to this android.graphicsTen //LEDs and so on are automatically cycled without setting the cycle interval like a vibration OneNotify. Ledargb =Color.green; ANotify. LEDOFFMS = +;//Show Time -Notify. LEDONMS = +;//Closing Time -Notify. Flags = Notificationflags.showlights |notify. Flags; the varPintent = Pendingintent.getactivity ( This,0, - NewIntent ( This,typeof(secondactivity)), pendingintentflags.updatecurrent); -Notify. Setlatesteventinfo ( This,"Notification Header","Notification Content", pintent); -Mgr.notify (0, notify);//notification ID and notification +};

It is said that this is the code of the 2.0 era, very old.

The initialization of MGR is

var Mgr = (Notificationmanager) getsystemservice (Notificationservice);

Of course, you can not use the weak variable, random slightly.

Here's the point.

var pintent = pendingintent.getactivity (This, 0,new Intent (this, typeof (Secondactivity)), Pendingintentflags.updatecurrent);

To check for a new activity, the first parameter is the context (it seems all about the context is this) the second parameter Balabala says a lot of results parentheses say it's useless, but you have to write. The third is to click the notification to launch which activity page, the fourth is to send a flag.

The purpose of this sentence is to execute the page when the user clicks the notification. Do not write, because the notice must be assigned to a place to go.

Finally, the notification is executed.

Another notation is said to be 3.0. As follows

1Btnbuilder.click + =Delegate2             {3                 varPintent = Pendingintent.getactivity ( This,0,NewIntent ( This,typeof(secondactivity)), pendingintentflags.updatecurrent);4                 varnotify =NewNotification.builder ( This)5. Setticker ("you have a new short message.")6                     . Setsmallicon (Resource.Drawable.Icon)7. Setcontenttitle ("Notification Header")8. Setcontenttext ("Notification Content")9. Setcontentinfo ("Lower right corner");TenMgr.notify (0, notify. Notification);//Duplicate notification ID will not be canceled the seemingly duplicate will become another ID One};

I appreciate the 3.0 notation. Simplicity and not simplicity. Everything can be done by point, and the parameter attribute is more than 2.0 notation. This writing can also be written on the vibration, flashing lights, sound, you can see for yourself which is.

So many updates today. The next update is estimated to start learning something about the system.

Summing up the experience of these days, installation aspects as far as possible to find a reliable simulator, I was in the simulator disadvantage, Xamrin version as far as possible up-to-date.

Code execution style is similar to MVC.

All events are instantiated first, to modify his various properties, and finally to execute. Instead of writing the web as before, the page draws a picture of the CS code directly written to execute. Almost everything needs to be instantiated.

var variable and strong type, own grasp which, I personally think that Var is actually good.

That's it. The next update will continue.

If there is any description unclear or wrong, please point out, I will change immediately, after all, I am also the first time to use this thing.

Reprint please indicate the source.

Xamrin developing Android Notes (ii)

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.