EricC

Code Snippets in MOTODEV Studio for Android

by Eric Cloninger (EricC) Motorola on 08-03-2009 04:42 PM - last edited on 08-04-2009 08:35 AM by Community Manager

Application development, whether for desktop or mobile, is 10% inspiration and 90% perspiration. MOTODEV Studio for Android has features that shift the ratio in favor of inspiration.

Code Snippets is one such feature, and it’s available in the lower left corner of the MOTODEV Studio perspective. When you launch MOTODEV Studio, you should see this perspective, but if not, it is accessible from the Window->Open Perspective menu. Code Snippets are often-used code, made available in template form, for you to drag and drop into your source files.  By using common and proven code for your work instead of entering the same sequences each time, you will achieve more stable and better performing applications.

One place where snippets can be useful is in the onCreate() method. In onCreate(), you find yourself doing the same things over and over. For example, you might wish to retrieve the shared preferences for your application. Using the Snippets view, either drag the words Retrieve shared preferences from Snippets into an opened source file, or double click on the item in the Snippets view and the code is entered at the cursor. Voilà, it’s that easy!

 

Code Snippets in MOTODEV Studio for Android

 

Code snippets are just pieces of code and not a full application, so you will often need to replace default values or include other necessary packages. In the case of the example shown in the screenshot, you would need to import android.content.SharedPreferences before the code will compile. Most of the errors you will encounter from using snippets can be resolved by replacing default values (often in UPPERCASE) or using the QuickFix tool (Ctrl+1) to let the IDE fix them.


Express Yourself!


Do you have a bit of code that you use over and over? Of course you do. You can add your own bits of code to the Code Snippets View and share with your friends, co-workers and those guys on the discussion boards.
 

Code Snippets in MOTODEV Studio for Android

 

To create your own snippets, start by clicking in the middle of the Snippets view and choose “Customize”. This will bring up a dialog where you can manage the existing snippets as well as adding your own categories and new items to your categories.

You cannot modify the categories or snippets that ship with MOTODEV Studio, but you can create your own categories and snippets within those categories. As you can see in the screenshot below, I’ve created a new category called “Eric’s Snippets” by right-clicking in the snippet list and choosing “New->New Category”.

 

Code Snippets in MOTODEV Studio for Android

 

 

Once you’ve created a category, you can add individual snippets by right-clicking on the category name and choosing “New->New Item”. With the new item, you can create the code template in the editing area at the bottom. After pressing “OK”, you can access your new template from the Code Snippets view.

 

Code Snippets in MOTODEV Studio for Android

 

If you have values that need to be entered by the user of your template, you can add them in the Variables editor on this screen. Simply create a new variable and provide a default value for the variable. When the code snippet is activated, the user is presented with a dialog asking for the value they wish to use. If they wish to use the default, they need only dismiss the dialog. If they wish to modify the values, they do so by modifying the values in the table at the top of the dialog and view them in the area below.

Code Snippets are only one of the cool new features that we’ve added to MOTODEV Studio and more new features are coming in the future. I hope that you will try our product and give us feedback on what works, what doesn’t, and what could work better.

Enjoy!

Eric Cloninger (@ericcloninger on Twitter)

Sr. Product Manager
MOTODEV Studio
 

Message Edited by DJ_Ksar on 08-04-2009 08:35 AM

Comments
by roni(anon) on 08-10-2009 07:46 AM

hi my son was playing with my motorola A1200

some how he has somehow changed the language

to asian and locked me out of my phone if you are able

to help me i would be most grateful ..

thank you for taking the tjme to read me e'mail..

Reards

RONI

by Community Manager on 08-13-2009 09:56 AM
hey Roni. Sorry for the issues on your phone. Unfortunately this blog is not the right place to ask your question.  Sorry to send you to someone else but go to the Motorola customer support web site at http://www.motorola.com/support  You should be able to find all the information you need on your phone there.
by Mo(anon) on 08-16-2009 01:30 PM

Hello,

 

Great job!  I have one question:  Is  Motodev Studio sdk limits in anyway the end product (apk app) to run on Motorola Android based devices?  I would like to switch to Motodev but I want to make sure apps done with your sdk would run on any android devices to cell network. 

 

I also have  second question if I may: Whatwould you say theMotodev Studio benefits are versus the regular Google Android sdk?

 

Thanks.

 

Mo,

by Eric Cloninger (EricC) Motorola on 08-16-2009 02:43 PM

Hi Mo,

 

You can use MOTODEV Studio to create Android applications that will run on any Android device that supports the 1.1 or 1.5 (Cupcake)  runtime. That includes the HTC G1, Google ADP1, HTC Hero, etc. as well as upcoming handsets from Motorola. For what it's worth, quite a few of us at Motorola write Android apps in our spare time and we also use Studio.

 

Join us on the MOTODEV discussion boards as well.

 

Thanks for  your interest in MOTODEV. 

 

-E

by Karthik(anon) on 08-19-2009 05:14 AM

Hi,

I would be really interetsed to start using motoDev environment from the normal ADT provided by google. Lemme know is their any added advantage of using this one like drag and drop options and stuffs which makes basic programming easier and makes one think and do the logics ??

by Eric Cloninger (EricC) Motorola on 08-19-2009 06:04 AM

Hi Karthik,

 

There are convenience features built into MOTODEV Studio that will assist you in writing your Android app. Studio contains the ADT itself, so everything that ADT provides is also available to you.

 

Regards

 

-E

 

by Vikrant(anon) on 12-14-2009 12:51 PM

Hi

Can you please let me know if I develop apps for any other phone other than motorola, do I need to compile it with regular google sdk to compile it. Also do we have the driver supports and if i have both motodev and regular sdk, doest these interfere with each other or not?

 

 

Thanks

Vikrant

by Eric Cloninger (EricC) Motorola on 12-14-2009 12:59 PM

Hi Vikrant,

 

You can use MOTODEV Studio to develop for any Android phone, not just Motorola phones. We use the same SDK and debug connections that the standard Google SDK uses. So, if you can connect the phone and see it with 'adb devices', you can use MOTODEV studio.

 

Regards

 

eric

by jasonxia(anon) on 04-08-2010 12:09 AM

Hi,

 

This snippets is cool. I have a question about motodev. Can we run the emulator along, that means we don't need to run the emuator in motodev windows. or can I get this snippets and run it in eclipse?

by Eric Cloninger (EricC) Motorola on 04-08-2010 09:53 PM

Snippets aren't related to the emulator, so it won't help you with running the emulator externally.

 

If you want to remove the embedded emulator window, just close the emulator view and make sure the --no-window flag is *not* present in the properties for the AVD that you are launching in the emulator.

 

-E

Post a Comment
Be sure to enter a unique name. You can't reuse a name that's already in use.
Be sure to enter a unique email address. You can't reuse an email address that's already in use.
Type the characters you see in the picture above.Type the words you hear.
About MOTODEV Blog
The MOTODEV blog keeps you updated on mobile app development news from MOTODEV and the Android developer community.

Subscribe to our RSS feed Subscribe via RSS

Follow Us:
Fan MOTODEV on Facebook Join the MOTODEV LinkedIn Group MOTODEV on YouTube

Our Blog & Comment Policy
Opinions expressed here and in any corresponding comments are the personal opinions of the original authors, not of Motorola. The content is provided for informational purposes only and is not meant to be an endorsement or representation by Motorola or any other party.

Remember, when you comment, please stay on topic and avoid spam, profanity, and anything else that violates our user guidelines. All comments require approval by Motorola and can be rejected for any reason.

For customer support issues with your Motorola phone go to the Motorola customer support website.