1 Android and iOS analogy
Shared Preferences NSUserDefaults
SQLite Core Data
listen for events delegate
xml layout xib
activity stack UINavigationController
Intent UIViewController init()
Adapter data source and delegate
getView is very similar to cellForRowAtIndexPath:.
Another similarity you’ll notice is a pattern for reusing views, similar to iOS.
2 Fragments are mini controllers that can be instantiated to fill activities.
Also note that fragments do not have their own contexts and they rely heavily on activities for their connection to the application’s state.
Tablets are a great fragment use case example: you can place a list fragment on the left and a detail fragment on the right.
Fragments allow you to break up your UI and controller logic into smaller, reusable chunks.
Fragments are the new way of structuring apps on Android, just like UICollectionView is the new way of structuring list data instead of UITableView for iOS. While it is initially easier to avoid using fragments and instead use nothing but activities, you could regret this decision later on. That said, resist the urge to give up on activities entirely by swapping fragments on a single activity – this can leave you in a bind when wanting to take advantage of intents and using multiple fragments on the same activity.
ListViews are the closest approximation to UITableView on Android
Just like UITableView has a helper view controller, UITableViewController, ListView also has a helper activity, ListActivity, and a helper fragment, ListFragment
- Always work in dp (density-independent pixels) instead of pixels directly.
- Don’t bother nudging items for layouts in the visual editor – often the visual editor will put individual points of spacing on objects instead of adjusting the height and width as you might like. Your best bet is to adjust the XML directly.
If you ever see the fill_parent value for a layout height or width, this value was deprecated years ago in API 8 and replaced with match_parent.