Android Development tips for iOS developers

Source: Internet
Author: User
Tags versions

I've been working on iOS for five years, and I've been trying to avoid dealing with Android for a while-but things are different now. Whether you believe it or not, Android development is actually fun and not as different from iOS development as you might think.

I developed this "seven-minute Workout" application on the Android platform and learned a lot of valuable knowledge. I hope this article will share some of the tips also can help you solve practical problems. Note that what I'm going to do next is not necessarily exactly matched, and the focus of this article is not on Android development in its entirety; Of course, I will certainly mention all the experience I've accumulated in developing this simple application.

Ide

I chose to use Android Studio and I'm willing to bet that it will be the industry standard for the future as long as the test is complete. Although a lot of reports say it is not stable, but in my actual use, it only crashed once. Maybe I just got used to Xcode.

Java

No matter how you evaluate Java, it is simply a programming language. It solves the problem, and for seasoned developers, it's important to focus on the framework rather than on Java. I'm glad I don't have to be involved with EE.

iOS encryption

Mobile application Security Platform-love encryption, in the Android application encryption protection has DEX shell, unique so library encryption protection, resource file Protection. And the launch of the iOS application encryption protection, is the global initiative. From the local data, method body/method name, URL coding, program structure, network transmission data and other aspects of the iOS application of a full range of protection, and can be based on the needs of iOS users to provide customized solutions to achieve iOS anti-cracking protection. The following image is used before and after iOS application

Simulator

I've always thought the iOS simulator was a pain in the neck, but by contrast I found myself too young. After a bit of trying, I decided to give up the Android simulator and deploy the application directly to the actual device-unless people were willing to spend a lot of time staring at the screen.

Storyboard/nib

I've talked a lot about storyboard on my iOS development blog, and a lot of tough emails from readers who disagree with me have made me abandon this platform completely.

The layout format used by Android is XML. They are completely independent of each other. Android Studio also offers an excellent "WYSIWYG" editor:

But you can still dive into the original XML-if you want to (anyway I don't want to be so troublesome).

You can also choose other layout containers, such as relativelayout and framelayout, relative to the automatic layout. Here we can set the desired width, height, fill effect, border, and hue in pixels (i.e., the pixel capacity of the device) or matchparent, wrapcontant, and so on.

Wrap is very good for text content, it automatically adjusts the correct height and sets the appropriate size, and gives the rest to LinearLayout and other specific layout scenarios.

Although I haven't used it yet, fragment looks like a good way to reuse custom UI elements.

Uiviewcontroller

Android uses an activity to implement the Uiviewconroller function. Each screen/window is equivalent to an activity. This is where we handle most of the work, including binding data to the UI or handling events, and so on.

Controller/view Conversion

In iOS we use Segue, Pushviewcontroller, Presentcontroller and so on to migrate between different screens. But in the Android environment, we need to use intent.

You can easily migrate to a new activity, or even pass a subset of data to the past.

public void Onitemclick (...) {

Intent i = new Intent (Getbasecontext (), myactivity.class);

I.putextra ("row", position);

StartActivity (i);

}

In the new activity (that is, the myactivity in the above code), we can extract the data that is passed:

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 a variety of events, such as implementing table sharing:

Intent sendintent = new Intent ();

Sendintent.setaction (Intent.action_send);

Sendintent.putextra (Intent.extra_text, "Share this");

Sendintent.settype ("Text/plain");

StartActivity (sendintent);

Iboutlet

Perhaps everyone like me, in more than half of the case will forget to connect Iboutlet.

In Android, each scenario/component has a separate ID, and the content looks like this:

@+id/mybutton

It will then automatically generate a class named R, and then we can access the buttons in the code as follows:

Button button = (button) Findviewbyid (R.id.mybutton);

Label

One trick that iOS developers often use is to use scene tags to save search information, such as the displacement of the overall layout. In the Android environment, you can also add the entire object to the label, which is very practical.

Row.settag (data);

Uitableviewcontroller/uitableviewdatasource/uitableviewcell

The ListView on Android is the equivalent of UITableView on iOS.

And Uitableviewdatasource's Android counterpart is Arrayadapter:

Myadapter adapter = new Myadapter (this, r.layout.listview_item_row);

Listview.setadapter (adapter);

Where Listviewitemrow belongs to a line of layout, equivalent to UITableViewCell in iOS.

The adapter will then create/reuse each row in the GetView.

You can also set the title like this:

View Header = Getlayoutinflater (). Inflate (R.layout.listview_header_row, NULL);

Listview.addheaderview (header);

Pictures/Resources

With the help of the asset catalogue, image processing in the iOS environment becomes very easy, and typically developers only need to consider both the retina and the non-retinal screen (unless you want to use an ipad-specific image on the iphone).

Because of the different resolution of the devices in the Android camp, you have to provide the following four types of picture formats.

They are: mdpi (normal resolution), HDPI (high resolution), XHDPI (ultra-high resolution) and XXHDPI (Ultra high resolution). I personally think that the birth of the xxxhdpi version will only be a matter of time.

When you create a project from Android Studio, you only need to provide an icon, and it automatically creates these four formats. This belief has left a serious psychological shadow for friends who have worked on Android apps: Don't be afraid, you can then manually replace it with the perfect pixel version.

Therefore, the most basic solution is to create a separate version for each pixel density for each image, set the same name for it and put it under the correct folder, so Android will choose the ideal version depending on the specifics of the device platform.

Custom Fonts

Custom fonts are also very simple to implement on Android: Copy fonts into the main/assets and then invoke them using the following code:

typeface font = Typeface.createfromasset (Getassets (), "Lato-regular.ttf");

Textview.settypeface (font);

The problem is that this is not going to work on all devices, so you need to prepare a set of fonts-but neither of my own Android devices offer that font.

NSLog

The log seems to be nothing to talk about, and you can use it to debug your application (save 1000 words here). System.out.println (..) It also seems to be able to accomplish this task.

Backward compatibility capability

We've all heard about the fragmentation of Android devices. In essence, however, dealing with older versions of Android is no more difficult than using the new iOS feature on older versions of iOS. However, you may need to attach great importance to this kind of compatibility, after all, the Android environment such problems occur much more frequently than iOS.

We can check the current Android version with the following code:

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

...

}

The following code is used to prevent the warning message raised by a function call:

@SuppressLint ({"Newapi", "localsuppress"})

private void MyFunction () {

...

}

The long and strange journey of Android

Countdowntimer

The countdowntimer--of this built-in feature really excites me because it's what I need to do for my seven-minute workout application. However, after a practical test, it will not send the last ontick before OnFinish, which is a very strange bug and has not been repaired yet. Weird, it's just weird.

Position

When the user rotates the device, our activity is completely reset, which means that you must retain all state and recovery mechanisms for the activity after it has been loaded back in. The Android environment has a headache, but iOS handles it well.

Kindle Fire/amazon Store

To get your app into the Amazon Store, I just need to make two adjustments to the existing results:

· The YouTube SDK does not work because YouTube apps are not available on the Kindle Fire. But the ability to support Flash is still preserved.

• You need to buy code for the Amazon store replacement application.

You can use Android.os.Build.MANUFACTURER and Android.os.Build.MODEL to test the manufacturer and product model information of the equipment.

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.