Make Your First Android App
发布日期:2021-08-14 10:59:16 浏览次数:2 分类:技术文章

本文共 5539 字,大约阅读时间需要 18 分钟。

  • Activity Name. This is the first mention you’ve seen of the word Activity, but it certainly won’t be the last. In Android, an is usually thought of as a “screen” in your app. It could be fullscreen or it could be a partial-screen pop-up. It is very flexible. If you want your user interacting with something in your app, that’s at some level happening via an Activity.
    Note: When Android Studio creates your
    MainActivity, what it’s doing is making a subclass of
    Activity. Those familiar with object-oriented programming will know what this is, but for newcomers, this basically means that your
    MainActivity is going to be a customized version of
    Activity that acts just like the default one, handling things like its lifecycle and the user interface display.
  • Layout Name. You’re going to define your MainActivity in Java, but the layout of everything it will show to the user is defined in a special sort of . You will learn how to read and edit those files soon.
  • Fragment Layout Name. A is a little like a sub-activity, and can be a useful part of your app design. I won’t go into fragments much in this tutorial—in fact, one of the things you’ll do is remove the one that the New Project wizard makes for you—but I encourage you to further investigate how to effectively use fragments after you finish this tutorial.
  • Navigation Type. For now, just choose None. You won’t need any navigation for a little while, and when you do, it’ll be smarter to build it yourself, from scratch.
  • is a new build tool that is easy to use, but it also contains a lot of advanced options if you investigate it further. Basically, it takes your Java code and XML layouts, and uses the latest Android build tools to create the app package file, known as an APK file. You can customize your configurations to have development or production versions of the app that behave differently, or add dependencies for third-party libraries.
  • is another project build tool, and it can also refer to the of java libraries. It is absurdly easy to use Gradle and Maven Central in concert with Android Studio to incorporate all sorts of functionality from the Android development community. Those with an iOS background will know how cool this sort of thing can be from using the tool. You’ll learn more about Maven in Part Three of the tutorial.

Android Project Structure: The Team

Every great team is composed of people who play different roles. Do you want to do the job right? You need the right team. Android Projects have a few key elements and each has a role to play:

  1. Java: The Professional
  2. Resources: The Artist
  3. AndroidManifest.xml: The Boss
  4. Intent: The Job itself

Java: The Professional

It’s the job of your Java code to get things done. Your code is all going to be in the src\main\java directory under your main project folder. I’ll give you all the code you need to complete this tutorial, but if you want to learn or refresh your Java knowledge, here is .

It will be worth your time to learn more and more Java as you explore Android development. Your team is relying on the professional.

Resources: The Artist

It’s not enough to just get the job done. It needs to be done in style. Your app is never going to stand out unless it has great icons and images, well-designed layouts, engaging copy text, and maybe even some smooth animations.

Initially, the src\main\res () folder contains:

  • Drawable folders that hold images — just the default launch icon for now.
  • The layout folder with XML that represents the screen designs.
  • The menu folder with XML of the items that will appear on the Action Bar. More on that later.
  • The values folder with XML containing dimensions, strings, and styles.

AndroidManifest.xml: The Boss

Someone’s got to call the shots. That “someone” would be the . This XML file informs your system of the app’s hardware and software requirements and contains your app’s name, icon, and version.

The manifest also filters the Intents coming in. You need a job done by your app? Talk to the boss first. Now, more about the jobs themselves…

Intent: The Job itself

Want to show the user a screen? Want to navigate to a website? Whatever the job is, in Android it is going to take the form of an . If you come from an iOS background, pay close attention because this is a very “Android” concept.

The Android system knows that you will potentially have a lot of apps on your device, and wants to make it easy for them to talk to each other. So, it allows you to send and receive what are essentially requests for jobs to be done.

A job could get picked up by your app’s own boss (the manifest) or another app. When creating an Intent, it’s up to you to either write it very generally to have the option of picking from several apps to perform the job (implicit), or very specifically to follow a certain path (explicit). You’ll see an example of each type if Intent later in this tutorial.

For an immediate example, your app already has an Activity called MainActivity. Your manifest has it labeled with an intent filter that causes the MainActivity to launch when the user selects the app icon from their home screen. You could potentially move that filter to another Activity and then that activity would launch instead of MainActivity. Basically, the app does whatever the boss says.

If you don’t fully grasp everything about Intents right away, don’t worry. Just keep the concept in mind as you see Intents throughout the code, and eventually you will start to get an idea of their potential.

 

转载于:https://www.cnblogs.com/wingjay/p/3981421.html

转载地址:https://blog.csdn.net/weixin_30719711/article/details/98303296 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:jQuery操作样式知识总结
下一篇:通过重建清理SVN服务器无用目录,不丢失其他目录修改记录

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年03月29日 02时35分47秒