Android Developer advice for iOS developers

Source: Internet
Author: User

I have been engaged in iOS application development for more than 5 years, until now still deliberately avoid andriod application development. But whether you believe it or not, Android development is interesting, and the span from iOS to Android app development is not as big as you think.

Now I share with you some of the things I've learned in developing this Android app for 7 minutes and I hope to help you. It should be noted that each project I am comparing later is not exactly a match, and this article is not a complete overview of Android app development, but it contains a little bit of what I learned from developing this simple application.

Development environment

Development environment I chose Android Studio, and I bet it will become the standard development environment for Android apps when the release is released. Although there is a lot of talk about the instability of Android studio, but I only encountered a program crash, personally think that Android studio stability is fair, perhaps has adapted to Xcode's habitual program crashes.

Java

Tell me how much you know about Java and it's just another programming language. Like other languages, it helps you use your computer to realize your ideas, and if you are an experienced programmer, you will devote more effort to the architecture of your application than to the Java language itself. Thankfully, we don't need to learn the Java EE.

Simulator

Before using the Android simulator, I used to think that the iOS simulator was awful, and now it seems that the iOS simulator is still very strong. Do not use the Android simulator as far as possible, directly on the real machine debugging, or you are ready to spend a lot of time on the unnecessary waiting.

Storyboard/nibs

The use of Storybaord has been described in my previous iOS development article, and I have received a strongly worded letter from readers of different views on whether to use storyboard, and we will not discuss this today.

Android uses XML to write layouts. Different layouts are completely independent of each other. Android Studio also offers a very good wys| WYG Editor:

You can also go deep into the original XML file for editing (I do it myself often).

Various layout containers can be used as an alternative to automatic layout, such as Relative layout, framelayout, and so on. With the layout selected, you can set the pixel (DP device pixel) level for the layout's width, height, padding, left white, specific gravity, or directly set them to match parent, wrapcontent.

Wrap-content is a good choice for text, and it automatically determines the size of the view based on the text.

Although I am not accustomed to using fragments, it does seem to be a good way to reuse the custom interface.

Uiviewcontroller

Android is equivalent to iOS Uiviewcontroller is a component called activity. Each view and window you see is an activity. In activity, the most you do is bind the data to the UI, handle various events, and so on.

Transitioning Controllers/views

In iOS we use segues, Pushviewcontroller, presentcontroller to switch between different views. In Android, we use a component called intent.

You can easily use intent to create a new activity, or even pass some data to the newly created activity.

12345 public void onItemClick(...) {       Intent i = new Intent(getBaseContext(), MyActivity.class);       i.putExtra("row", position);       startActivity(i);}

In the newly created activity (myactivty shown above), you can extract the data passed by the activity in such a way.

1234567891011 protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_mine);     Bundle extras = getIntent().getExtras();    if (extras != null) {        int row = extras.getInt("row");        ....     }     ... }

You can also use intent to trigger something, such as: share a page.

12345 Intent sendIntent = new Intent();sendIntent.setAction(Intent.ACTION_SEND);sendIntent.putExtra(Intent.EXTRA_TEXT, "Share This");sendIntent.setType("text/plain");startActivity(sendIntent);
Iboutlet

If you're like me at least half the time forget to connect iboutlets,android will be your gospel.

Each view/component in Android has a unique ID, for example:

1 @+id/myButton

Android will automatically generate a class called R for these IDs (to learn more about R click here), you can manipulate the button object in the following way.

1 Button button = (Button)findViewById(R.id.myButton);
Tag

Setting a tag for a view to find information is a common tip for iOS developers, such as array offsets. And on Android you can tell this object to be set to tag, which is quite useful.

1 row.setTag(data);
Uitableviewcontroller/uitableviewdatasource/uitableviewcell

In Android, the ListView corresponds to the UITableView.

What corresponds to the Uitableviewdatasource is arrayadapter:

12 MyAdapter adapter = new MyAdapter(this, R.layout.listview_item_row);listView.setAdapter(adapter);

As in the example above, Listviewitemrow is a row in the layout, roughly equivalent to a uitableviewcell.

Adapter creates or re-uses different columns through GetView.

You can also set the table header:

12 View header = getLayoutInflater().inflate(R.layout.listview_header_row, null);listView.addHeaderView(header);

There are a lot of good tutorials on the internet, such as this one.

Images/resources

Since asset catalogues has appeared on iOS, it has been a lot easier to handle images, and only needs to deal with retina and non-retina screens (unless you have a picture specifically for ipad).

To accommodate the resolution of different Android devices, you need to provide four different sizes of images.

They are: mdpi (medium quality), hdpi (high quality), xhdpi (Ultra high Quality), xxhdpi (the universe is invincible high quality). Individuals are looking forward to the appearance of xxhdpi quality.

When you create a project in Android studio, it automatically generates four different size icons for the app icon you provide. It's scary for the designers, don't worry, they can be replaced by the perfect icon later.

So, the basic idea is to correspond to different screen resolution to create a different picture, and with the corresponding screen resolution of the name, put into the correct folder, after the matter to the Android to deal with it.

Custom Fonts

Custom fonts are also fairly easy to implement in Android: Copy fonts to the Main/assets folder, and then you can call them like this:

12 Typeface font = Typeface.createFromAsset(getAssets(), "Lato-Regular.ttf");textView.setTypeface(font);

This method is not feasible on all devices, it is best to add the Try/catch method to handle the exception, that is, on my two Android devices have never experienced an exception.

NSLog

It seems that log is the solution that Android gives us, you specify the type of log: Debug, verbose, and so on. Of course, Java's most basic print statement System.out.println (..) is also well-done.

Backwards compatibility

We often hear of Android fragmentation. The solution to this problem in Android is basically the same as when we use the new features of iOS and take care of the old version. You may need to use these techniques more often and longer.

Android has a very useful constant for you to query the current Android API version number.

123 if (Build.VERSION.SDK_INT >= 11.0)  {...}

You can do this to block the warning:

1234 @SuppressLint({"NewApi", "LocalSuppress"})private void myFunction() {...}

Something surprising.

Timer

I am very excited about the features of the Android built-in timer, which is what I need to develop 7 minutes of training. But it does not send the last signal before the end of the time, it is such a surprising bug, still not be repaired. Annoyed, too irritated!

Screen orientation

When the user rotates the screen, the activity is completely reset, which means you need to save all the status before the activity is reset and restore the status after the activity continues. This may make you feel a little surprised, because rotating the screen in iOS, you do not need to do any processing, as usual.

Kindle Fire/amazon Store

It's pretty easy to publish apps in the Amazon store, I just want to say two points:

    • The YouTube SDK will stop working because it requires support from the YouTube app, and the YouTube app is not available here, but it seems to support Flash.
    • For the Amazon store, you need to clear the source code inside the purchase code.

You can do this by using Android.os.Build.MANUFACTURER and Android.os.Build.MODEL. To inquire about the manufacturer and model of the device.

A list of Kindle Fire model details is available here.

Next?

Hopefully in the future I'll be able to add more features to the 7-minute training app and develop more Android apps. I believe I only saw the tip of the iceberg of Android. Who knows, maybe next there's a great tutorial on the App Store waiting for you.

Android Developer advice for iOS developers

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.