App Development with Visual Studio

App Development with Visual Studio

Let us see how we can do app development with Visual Studio.The Android working framework depends on the Dalvik Virtual Machine (VM), which is a versatile upgraded VM like the Java VM. Oxygene for Java ships with layouts for making Android projects, and creates both local Java JAR documents and the Android APK record vital for organization to an Android gadget. 

Check this link if you have not installed Visual studio yet

Begin with visual studio

Since Android runs on such a wide assortment of gadgets with various screen sizes, arrangements and directions, it was deliberately planned without a WYSIWYG structure surface for building the UI. Rather, a XML record (like .NET's XAML) is altered to spread out the visual components. There is a free online DroidDraw apparatus for building Android User Interfaces by means of a WYSIWYG interface, however altering the XML straightforwardly is suggested.

Prerequisites and Emulators

To begin with Android advancement, you have to introduce the Java Development Kit and Android SDK, as plot here (Fire) and here (Visual Studio). 

At the point when the instruments and stages are totally introduced, you will have the option to make an Android Emulator, otherwise called an Android Virtual Device or AVD. You can do this from the Android Virtual Device Manager, which is open from the SDK Manager by picking Tools, Manage AVDs. 

Simply click New, give the emulator a name and select the API in the Target field. You can pick any introduced API level, for instance Android 2.2 - API Level 8 (otherwise called Froyo) or Android 4.0.3 - API Level 15 (otherwise called Ice Cream Sandwich). When you've determined the SD Card Size for the emulator (state 512) and picked a skin (a screen goals) you can utilize the Create AVD catch to complete the activity.

App development with Visual Studio

 Launch the emulator from this screen by selecting it and pressing the Start button.

Android Manager

Note: When you re-run the SDK Manager, it will frequently discover updates to introduce. As referenced before, if the Android SDK was introduced into the default area, it will require regulatory benefits to introduce them. So make certain to run it as Administrator (or introduce the Android SDK into a custom area to make things less difficult). 

The first occasion when you make or open an Elements venture for Android, it will do a 'pre-flight check' to guarantee that it can find the things it needs, remarkably the JDK and the Android SDK. On the off chance that you've introduced them into custom areas and it neglects to discover them, this offers you a chance to indicate the establishment envelopes. 

Getting Started

In both Visual Studio and Fire, the New Project exchange gives the Android application format under Oxygene for Java and Android.Visual Studio 2012 - Oxygene for Java - Android - New project

The new Android project is made with a solitary straightforward action called MainActivity. An Activity is the most fundamental piece of an Android application – a solitary, centered thing that the client can do. The pre-made MainActivity contains a limited quantity of code to set up a basic UI with a catch that, when clicked, shows an augmenting depend on its subtitle. 

The visual portrayal of the screen for MainActivity is characterized in the XML record ''main.layout-xml'' which is in the ''res/format'' envelope.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="" android:orientation="vertical"
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  <LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    <Button android:id="@+id/MyButton" android:text="@string/my_button_text"
      android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

Controls are named with the android:id trait in design XML. You prefix @+id/before the picked name and you would then be able to reference the control's ID in code by prefixing it with (all IDs become individuals from the id class, which is settled inside the R asset class). To get to the control, you can pass the ID into the movement's findViewById() strategy. For instance, the catch named in the design XML above has an ID open in code as To gain admittance to the catch object you'd use

Button(findViewById( - notice the pigeonhole to get a Button  object, which is required in light of the fact that findViewById() restores a View  object, one of the Button class' progenitor types. 

Strings referenced in the XML qualities with the @string/prefix or in the code as individuals from the R.string class are characterized in the '''' asset record, which can be found in the ''res/values'' envelope.

<?xml version="1.0" encoding="utf-8"?>
  <string name="app_name"></string>
  <string name="my_button_text">Click Me!</string>
  <string name="my_button_text_2">%1$d clicks!</string>

To reference the string asset in code from an action technique, you essentially call getString(R.string.my_button_text). getString() is a technique for theActivity class (or, all the more precisely, a strategy for one of Activity's progenitor classes, Context). As should be obvious, you pass a string asset ID to the technique and it restores the resultant comparing string. 

Note: In Delphi and in .NET dialects we are accustomed to working with properties. A property speaks to certain information with conceivable symptoms when perused from as well as when written to. A property Foo is characterized as far as a getFoo() getter work that profits a worth and a setFoo() setter capacity that is passed a worth. Java doesn't bolster the thought of properties, so classes have numerous getter and setter strategies uncovered rather than their proportionate properties. When working with Oxygene for Java, you have the decision of calling the getter/setter sort strategies that exist in any Java libraries that you reference, for example, the Android SDK, or utilizing the property that you may regularly hope to exist. So for the situation above, you can get to a string asset either by calling:

  MainActivity = public class(Activity)
    Count: Integer := 0;
    method onCreate(savedInstanceState: Bundle); override;
    method ButtonOnClick(v: View);


method MainActivity.onCreate(savedInstanceState: Bundle);
  // Set our view from the "main" layout resource
  ContentView := R.layout.main;

  // Get our button from the layout resource,
  // and attach an event to it
  var myButton: Button := Button(findViewById(;
  myButton.OnClickListener := new interface View.OnClickListener(onClick := @ButtonOnClick);

method MainActivity.ButtonOnClick(v: View);
  (v as Button).Text := WideString.format(String[R.string.my_button_text_2], Count);

onCreate is the strategy considered when the movement is first made and where your action initialisation goes. In the wake of calling through to the acquired strategy, you can see that a format asset ID is doled out to the ContentView property, albeit given the note above, it ought to be evident that truly we are passing the asset ID to setContentView(). This sets up the design document ''res.layout-xml'' as the UI for this fundamental action. 

Next the code finds the catch with the ID MyButton and stores a reference to it in a nearby factor. 

The last employment of onCreate() is to set up the catch's snap occasion handler, which is finished by allotting an articulation to the catch's OnClickListener property, or in truth passing it to the setOnClickListener() technique. Since Java utilizes interfaces to characterize occasion marks, we utilize Oxygene's inline interface usage to connect our ButtonOnClick technique with the onClick strategy for the catch's  View.OnClickListener occasion interface. 

The occasion handler technique itself, ButtonOnClick, increases the Count class occurrence variable and afterward utilizes the incentive to make an arranged string, which is then set as the catch's inscription by means of its Text property (or  setText() strategy). The string arranging utilizes the estimation of the my_button_text_2 string asset (demonstrated prior), which utilizes Android format string syntax. The arranging strategy being called is truly String.format(). It's being called as WideString.format() to dodge uncertainty with the String property (getString() technique) for the Activity class we took a gander at simply above. WideString is given by Oxygene as an equivalent for the  String type. 

One extremely significant incentive in the '''' record is the app_name string. This is utilized twice by the application: 

  • the movement's title bar has this string composed on it and 
  • the rundown of introduced applications on the gadget utilizes this string to distinguish the application. 
  • Make certain to refresh app_name to make it significant. 

You can discover the references to app_name that influence the title bar and the introduced application list in the [ intro.html Android show file], '''' in the ''Properties'' organizer. Each Android application has a show record to tell Android the personality of the application bundle, the parts in the application, any authorizations required so as to work and some other framework subtleties.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
  <application android:persistent="true"
    <activity android:label="@string/app_name" android:name="">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
  <uses-sdk android:minSdkVersion="4" />

In this example application's show you can see the application is given a content mark and a symbol, and the single movement is recognized by its group name and furthermore given a name. The tangled looking expectation channel revelation inside this movement is basically the standard code important to disclose to Android this action is the principle action of the application. 

At the point when you have to add more strings to your undertaking, basically alter the '''' record. 

Note: The different Android asset records that dwell inside the ''res'' envelope progression are all XML documents. They would all be completely substantial and usable whenever given the norm .xml expansion. The purpose behind the .design xml and .android-xml expansions is to empower the proper IntelliSense (or Code Completion) conduct when working in these records. 

Running Your App 

At the point when you manufacture your application, the Oxygene compiler initially makes a typical Java JAR record and afterward the Android toolchain makes an Android APK document (Android PacKage). The JAR record is simply arranged code (Java byte code) yet the APK document is the Java byte code handled to run on Android's Dalvik Virtual Machine with all the essential assets bundled into the record. When the bundle is constructed, it is prepared to run either on an AVD (as it were on the emulator) or on a physical gadget. 

Note: To convey an APK record from your Windows machine to a physical gadget, for example, a telephone or tablet, you should initially introduce the maker's USB driver for the gadget to permit correspondence between the PC and the gadget. At that point you interface the gadget to the PC utilizing a suitable USB link. You ought to have the option to find guidelines on the most proficient method to introduce the driver on your producer's site or by utilizing a web search tool. 

The Oxygene debugger will consequently send the APK to the emulator and dispatch it when you utilize the Start Debugging or Start Without Debugging catches in Visual Studio (or utilize the F5 or Ctrl+F5 keystrokes, individually). On the off chance that you pick Start Debugging (or F5), you can set breakpoints and investigate your application from Visual Studio as it runs on the emulator or physical gadget. 

On the off chance that you have a virtual Android gadget running and furthermore have a physical Android gadget associated with the PC, you need some approach to disclose to Oxygene which gadget to target when you start an application. You can pick an Android gadget in the Android area of the task properties. 

On the off chance that you need to introduce the APK physically, you can utilize the Android Debug Bridge (ADB) order line apparatus from a Windows order brief. The adb.exe apparatus is situated in the ''<Android_SDK_installation_path>\android-sdk-windows\platform-instruments'' organizer, where ''<Android_SDK_installation_path>'' could be ''C:\Program Files'' or another registry you picked at establishment time. It might be good for include both ''<Android_SDK_installation_path>\android-sdk-windows\platform-devices'' and furthermore ''<Android_SDK_installation_path>\android-sdk-windows\tools'' to the framework search way to empower Android SDK devices to be executed by name regardless of what the ebb and flow catalog is. 

Basically run adb with the introduce parameter and the name of the APK to stack. On the off chance that the APK is as of now introduced, you ought to likewise indicate the - r. Accepting that adb's catalog has been added to the inquiry way, you would utilize: 

adb install -r

'''Note''': If you have an emulator running and a physical gadget appended to the PC, you can utilize the - d and - e changes to indicate either the gadget or the emulator, separately, for instance: 

adb -e install -r

Android Emulator - Deployed

Once the APK is installed, you can run it just like you would any other app.

Android Emulator - Running

UI Elements 

The <LinearLayout> tag in ''main.layout-xml'' is one of a few design choices. A portion of different designs are FrameLayout, TableLayout and RelativeLayout. 

FrameLayout - A casing format is intended to shut out a territory on the screen to show a solitary thing. 

LinearLayout - A format that orchestrates its kids in a solitary section (vertical) or a solitary line (level). The default direction is flat. 

RelativeLayout - A design where the places of the kids can be portrayed comparable to one another or to the parent. 

TableLayout  - A design that organizes its youngsters into lines and segments. A TableLayout comprises of various TableRow objects, each characterizing a line. TableLayout compartments don't show verges for their lines, sections, or cells. Each line has at least zero cells; every cell can hold one View object. The table has the same number of sections as the column with the most cells. A table can leave cells unfilled. Cells can traverse sections, as they can in HTML. 

Once you have the layout, you can add other controls like ButtonImageButtonTextViewImageView and others. 

There is a quite decent UI instructional exercise accessible. Remember that the code tests will be in Java rather than Oxygene. Be that as it may, you should find that the Oxidizer IDE highlight can help in porting Java code over to the Oxygene grammar. In the event that you have a scrap of Java code in the clipboard, you can press Alt+Ctrl+V, at that point J and the Oxidizer will do its most extreme to decipher the code for you. It won't really make an ideal showing as it's working without setting, yet it ought to do the primary greater part of the interpretation for you.

Oxidizer can port Java snippets to Oxygene

Now for some Toast

When you want to popup a message to your users from an Android app, you make toast. A toast is a small popup window that shows up in front of the current activity for a short time. Simply call the makeText method on the Toast class to create a toast object, then call show() to pop it up on-screen. There are two versions of makeText and each takes 3 parameters. Here is a sample call:

Toast.makeText(self, "Hello World! This is a toast.", Toast.LENGTH_SHORT).show();

The main parameter is the setting that the toast identifies with. You can either pass your movement (utilizing self if working in the action's strategy) or a reference to the single application object that exists in the application (available by means of the action's getApplicationContext() technique), since both Activity and Application acquire from the  Context class. 

The subsequent parameter is the content string to show. This can either be an exacting string as above or, ideally, a string asset ID, contingent upon which rendition of makeText you are utilizing. So to pass an asset ID, you would reference a string characterized in '''' by utilizing String[R.string.some_identifier]. 

The last parameter is the span before the toast is auto-excused, either Toast.LENGTH_SHORT or  Toast.LENGTH_LONG.

The call to makeText restores a Toast object. There are different strategies on the Toast article to arrange it. The show strategy eventually shows the toast. 

Simply add the code above to the ButtonOnClick occasion handler in MainActivity and when you run it in the emulator or on a gadget, you will see the toast show up when you click the catch.Android Emulator - Running with Toast

A toast never receives focus and always disappears after the duration timeout.


For Android documentation, you can utilize the mass of data gave by Google in their API Reference and API Guides. Normally, this documentation is focused at Java software engineers, however that should be only a minor burden - the technique marks are spread out in C-style linguistic structure as opposed to Pascal-style. Oxygene can locally get to any of the Android SDK class and call any of the accessible strategies, so the best documentation is the documentation composed by the stage supplier: Google. 

In this groundwork, different distinctive class types and techniques have been connected through to the comparing Android SDK documentation. You should get comfortable with utilizing the Android SDK documentation to find out about how to program Android applications in Oxygene for Java. 


One significant thing to recollect for Android as you begin building bigger tasks and utilizing extra libraries is that in the event that you don't set the "Duplicate Local" property to valid for a referenced library, the compiler presumes the library is accessible on the framework and does exclude it in the created file. In the event that you set it, it turns out to be a piece of the application. For the principle stage library, for example, android-14, "Duplicate Local" must be left as bogus, however for every single other library it must be set to consistent with guarantee the referenced code will be accessible when the application runs on an Android gadget.

Post a Comment