Android development skills and iOS Android development skills for iOS developers
I have been engaged in iOS application development for five years. During that time, I tried to avoid dealing with Android as much as possible-but now the situation is different. Whether you believe it or not, Android development is actually fun, and it is not as different as you think.
I developed this "7-minute workout" application on the Android platform and learned a lot of valuable knowledge. I hope some tips shared in this article can help you solve practical problems. Note that the content to be compared does not necessarily match exactly, and the focus of this article is not to fully describe Android development. Of course, I will certainly mention all my experience accumulated in the process of developing this simple application.
IDE
I chose to use Android Studio, and I am willing to bet that as long as the test is complete, it will become the industry standard in the future. Although many reports say that its running status is unstable, it only crashes once in my actual use. Maybe I just get used to Xcode.
Java
No matter how you evaluate Java, it is just a programming language. It can solve the problem, and for experienced developers, you must focus on the framework rather than Java. I'm glad I don't need to talk to J2EE.
IOS Encryption
Mobile app security protection platform-love encryption. In terms of Android app encryption protection, dex shelling, exclusive so library encryption protection, and resource file protection are provided. In addition, it has launched encryption protection for iOS apps, which is the first in the world. The iOS application is protected in an all-round way from the aspects of local data, method body/method name, URL encoding, program structure, and network transmission data, you can also provide customized solutions based on the needs of iOS app users to implement anti-cracking protection for iOS. Before and after iOS apps
Simulator
I always think that the iOS simulator is a headache, but in comparison, I found myself too young. After a few attempts, I decided to abandon the Android simulator and directly deploy the application on the actual device-unless you are willing to spend a lot of time staring at the screen.
Storyboard/NIB
I talked a lot about Storyboard on my own iOS development blog. Many readers who disagree with me sent some hard-coded emails, which gave me a complete waiver of this communication platform.
The layout format used by Android is xml. They are completely independent of each other. Android Studio also provides an excellent "WYSIWYG" Editor:
But you can still go deep into the original xml-if you want to (I usually don't want to be so troublesome ).
Compared with automatic layout, you can also select other layout containers, such as RelativeLayout and FrameLayout. Here, we can set the ideal width, height, fill effect, border, and color based on the number of pixels (that is, the device's pixel capacity), matchparent, and wrapcontant.
Wrap is very suitable for text content. It automatically adjusts the correct height, sets the appropriate size, and submits the remaining work to specific layout schemes such as LinearLayout.
Although I have never used it, Fragment seems to be a good way to reuse custom UI elements.
UIViewController
Android uses an Activity to implement the uiviewconroler function. Every screen/window is equivalent to an Activity. We will handle most of the work here, including binding data to the UI or handling events.
Controller/View Conversion
In iOS, we use segue, pushViewController, and presentController to migrate data between different screens. However, in the Android environment, Intent is required.
You can easily migrate to a new activity, or even pass a part of the data.
public void onItemClick(...) { Intent i = new Intent(getBaseContext(), MyActivity.class); i.putExtra("row", position); startActivity(i); }
In the new Activity (MyActivity in the above Code), we can extract the transmitted data:
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 various events, such as 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
Maybe, just like me, more than half of them will forget to connect to IBOutlet.
In Android, each scenario/component has an independent ID. The content is as follows:
@+id/myButton
It will then automatically generate a class named R. Next we can access the buttons in the Code as follows:
Button button = (Button)findViewById(R.id.myButton);
Tag
IOS developers often use scenario tags to store search information, such as the overall layout shift. In the Android environment, you can add the entire object to the tag, which is very practical.
row.setTag(data);
UITableViewController/UITableViewDataSource/UITableViewCell
In Android, ListView is equivalent to UITableView on iOS.
In Android, UITableViewDataSource corresponds to ArrayAdapter:
MyAdapter adapter = new MyAdapter(this, R.layout.listview_item_row); listView.setAdapter(adapter);
Listviewitemrow belongs to the layout of a row, which is equivalent to UITableViewCell in iOS.
The adapter then creates/re-uses each row in getView.
You can set the title as follows:
View header = getLayoutInflater().inflate(R.layout.listview_header_row, null); listView.addHeaderView(header);
Images/Resources
With the help of Asset Catalogue, image processing in the iOS environment becomes very easy, generally, developers only need to consider the Retina screen and non-Retina screen (unless you want to use images for iPad on the iPhone ).
Because the resolutions of various devices in the Android camp vary widely, you must provide the following four image 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 xxxhdpi is only a matter of time.
When using Android Studio to create a project, you only need to provide an icon and it can automatically create the four formats. This practice is believed to have left a serious psychological shadow for those who have been engaged in Android Application Development: Do not worry, you can manually replace it with the perfect pixel version.
Therefore, the most basic solution is to create a separate version for each image for each pixel density, set the same name for it and put it under the correct folder; in this way, Android selects the desired version based on the actual situation of the device platform.
Custom font
The implementation of custom fonts on Android is also very simple: copy the fonts to main/assets, and then use the following code to call them:
Typeface font = Typeface.createFromAsset(getAssets(), "Lato-Regular.ttf"); textView.setTypeface(font);
The problem is that this method does not work on all devices, so you need to prepare a backup font. However, neither of my own Android devices provides such a font.
NSLog
There seems to be nothing to say about the log. You can use it to debug the application or something (one thousand words are omitted here ). System. out. println (...) seems to be able to accomplish the same task.
Backward compatibility
We have heard about the fragmentation of Android devices. However, in essence, it is not more difficult to process the old version of Android than to use the new version of iOS. However, you may need to pay great attention to this compatibility capability. After all, this type of problem occurs more frequently in the Android environment than in iOS.
You can use the following code to check the current Android version:
if (Build.VERSION.SDK_INT >= 11.0) { ... }
Run the following code to prevent warning messages caused by function calls:
@SuppressLint({"NewApi", "LocalSuppress"}) private void myFunction() { ... }
A great journey to Android
CountDownTimer
CountDownTimer-I am excited by the existence of this built-in function, because it is essential for my seven-minute workout application. However, after actual testing, it will not send the last onTick before onFinish. This is a very strange bug and cannot be fixed until now. It's weird.
Location
When a user turns the device in his/her hand, our activity will be completely reset, which means that you must retain all the statuses and recovery mechanisms for the activity after it is re-loaded. The Processing Method in the Android environment is a headache, but iOS handles well.
Kindle Fire/Amazon Store
To allow my applications to smoothly enter Amazon Store, I only need to make two adjustments to the existing results:
· The YouTube SDK cannot work because the Kindle Fire does not provide a YouTube app. However, the Flash support capability is retained.
· You need to purchase code for replacing an application with Amazon Store.
You can use android. OS. Build. MANUFACTURER and android. OS. Build. MODEL to check the device MANUFACTURER and product MODEL information.