Android development suggestions for iOS developers and android for ios developers

Source: Internet
Author: User

Android development suggestions for iOS developers and android for ios developers

I have been engaged in iOS application development for more than five years. Until now, I still deliberately avoided developing Android applications. However, whether you believe it or not, Android development is still very interesting. The span from iOS to Android Application Development is not as large as you think.

Now, I want to share with you some things I learned during 7-minute training of this Android app, hoping to help you. It should be noted that each project I compared later is not exactly matched, and this article is not a complete Android Application Development overview, however, it covers what I learned from developing this simple application.

Development Environment

I chose Android Studio as the development environment. I bet that when the official version is released, it will become the standard development environment for Android applications. Although there are a lot of comments about the instability of Android Studio, I only encountered a program crash. I personally think that the stability of Android Studio is acceptable. Maybe it has adapted to Xcode's habitual program crash.

Java

Let's talk about how much you know about Java. To put it bluntly, it is just another programming language. Like other languages, it helps you use computers to implement your ideas. If you are an experienced programmer, you will devote more energy to the application architecture, instead of Java. Thank God, we don't need to learn J2EE.

Simulator

Before using the Android simulator, I used to think that the iOS simulator is terrible. Now it seems that the iOS simulator is still very powerful. If you don't need an Android simulator, try your best to use it and debug it directly on the real machine. Otherwise, you will be ready to spend a lot of time waiting.

Storyboard/NIBS

The use of storybaord has been explained in my previous articles on iOS development, and I have received a letter with strong wording from readers who have different opinions on whether to use Storyboard, we will not discuss this today.

Android uses xml to write the layout. Different la s are completely independent of each other. Android Studio also provides a very good WYS | WYG Editor:

You can also go deep into the original xml file for editing (as I often do ).

Various Layout containers can be used as an alternative to automatic Layout, such as Relative Layout and Framelayout. After the layout is selected, you can set the layout width, height, fill, white, weight, and other attributes at the pixel level (dp device pixel), or directly set them to match parent, wrapcontent.

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

Although I am not used to fragments, it seems to be a good way to reuse custom interfaces.

UIViewController

Android is equivalent to iOS UiViewController. It is a component called Activity. Each view and window you see is an Activity. What you do most in an Activity is to bind data to the UI and process various events.

Transitioning Controllers/Views

In iOS, we use segues, pushViewController, and presentController to switch between 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 transmitted by the previous Activity in this 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, for example, 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 forget to connect to IBOutlets at least half of the time like me, 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 named R for these IDs (for more information about R, click here). You can operate on this Button object in the following way.

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

Setting a tag for the view to find information is a common trick for iOS developers, such as array offset. In Android, you can set this object as a tag, which is quite useful.

1 row.setTag(data);
UITableViewController/UITableViewDataSource/UITableViewCell

In Android, ListView corresponds to UITableView.

Generally, ArrayAdapter corresponds to UITableViewDataSource:

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

In the above example, listviewitemrow is a row in the layout, which is basically equivalent to a UITableViewCell.

The Adapter uses getView to create or reuse different columns.

You can also set the header:

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

There are many related tutorials on the Internet, such as this.

Images/Resources

Since the emergence of Asset Catalogues in iOS, image processing has been much easier, and you only need to deal with retina and non-retina screens (unless you have images specifically for iPad ).

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

They are: mdpi (medium quality), hdpi (high quality), xhdpi (super high quality), xxhdpi (universe invincible high quality ). I am looking forward to the appearance of xxhdpi.

When you create a project in Android Studio, it automatically generates four icons of different sizes for the app icons you provide. This can shake the hearts of designers. Don't worry, they can still be replaced by perfect icons later.

Therefore, the basic idea is to create different images corresponding to different screen resolutions, and name the corresponding screen resolutions, and put them in the correct folder, then, let's go to Android.

Custom font

Custom fonts are also quite easy to implement in Android: copy the fonts to the main/assets folder, and then you can call them as follows:

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 exceptions, that is, there has never been any exception on my two Android devices.

NSLog

It seems that Log is a solution provided by Android. you specify the log Type: debug, verbose, and so on. Of course, the most basic printing Statement of Java is System. out. println.

Downward compatibility

We often hear about Android fragmentation. The solution to this problem in Android is basically the same as the solution we used when using new iOS features and taking into account the old version. You may need to use these skills more frequently and for a longer time.

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

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

You can block the warning as follows:

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

Something amazing

Timer

I am very excited by the built-in timer function of Android, which is exactly what I need to develop 7-minute training. However, it does not send the last signal before the end of the timer, which is such a strange bug and is still not fixed. Angry, so angry!

Screen direction

When a user rotates the screen, the activity is completely reset, which means that you need to save the status before all the activities are reset and restore the status after the activity continues. This may make you feel a little surprised, because you do not need to do anything to rotate the screen in iOS, and everything is the same.

Kindle Fire/Amazon Store

Publishing apps in the Amazon store is quite simple. I just want to talk about two points:

  • The YouTube SDK will stop working because it requires support from the Youtube app, which is unavailable here, but it seems that they support Flash.
  • For the Amazon store, you need to clear the internal purchase code in the source code.

You can query the MANUFACTURER and MODEL of a device by using android. OS. Build. MANUFACTURER and android. OS. Build. MODEL.

A list of kindle fire Model details is provided here.

Next?

In the future, I hope that I can train this application in 7 minutes to add more features and develop more Android applications. I believe I only saw the tip of the iceberg of Android. Who knows? Maybe there will be some wonderful tutorials for you to explore the App Store.

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.