Udacity Android Learning Note: Lesson 3

Source: Internet
Author: User

Udacity Android Learning Note: Lesson 3

/titer1/archimedes of dry Goods shop chores
Source: Https://code.csdn.net/titer1
Contact: 13,073,161,968
Disclaimer: This document is licensed under the following protocols: Free reprint-Non-commercial-non-derivative-retention Attribution | Creative Commons by-nc-nd 3.0, reproduced please specify the author and source.
Tips:https://code.csdn.net/titer1/pat_aha/blob/master/markdown/android/

    • More activity Learn
    • Intent Framework
    • Content as a learning note, estimated to be divided into three parts later
Theory

Start baby steps

Click Item's Event response

The key is Itemclicklistener.

Debugging a sharp-edged toast

Somewhat similar to the Afxmessage in MFC ( ̄▽ ̄) "How to implement Afxmessage in threads recently"

Itemclicklistener + Toast Code Practice

Detail activity

Lesson 3-8 leads to detail activity

Practice


When the new activity (detailactvity) succeeds, the following files are added

    • New Activity Java file (Eg:DetailActvity.java)
    • Relative fragment (Eg:fragment_deatil.xml)
    • Relatvie Layout (eg:activity_deatil.xml)
    • Others such as anroidmanifest are changed
Intents Framework

When one activity moves to another activity, the startactivity is used, and the parameter is intent

一种直觉,感觉intent封装了类似c的线程间通讯(2个activity)+进程间通讯(2个app)

When it is 3-11 hours, Rado explains the following:

Intent content should contain:
-Not class name
-but action did by another activity
-The data The action should be performed

Lauch deatilactivity Code Practice

Replace a previous Toast

扩展:隐藏式/显式 intent区别

Remove code from previous toast, change to intent
The initialization of the intent is the initialization of the key-value pairs, and here is the explicit intent

和传统的mfc事件编程相比,这里站在更高的抽象层次。mfc是一个listitem对应一种事件,我用过的mfc,每个事件和一个固定的Itemid绑定。

In this way, only the intent filled content is resolved, and the next step is to parse the content passed by intent in detailactivity.

Display Content detailactivity Code practices
貌似 ctrl+o 提示 在这里大显身手,待实践证明todo:在群上 有对工具的分享,alt+enter 自动类型转换的提示


-Get Intent
-Display in DetailView

3_16课 很耍宝,( ̄▽ ̄)"当前setting 会不会工作啊,待实践证明
Setting UX

Wire frame diagram

If you need scientific requirements design, you can refer to the following:

The above flowchart will tell you what you can do and what not to do

Shared preference

For the first time, intuition is a system that can be reused setting?

Android developer options have a lot of setting design reference


It has code that takes you directly to the preference of the system,
Each prefence corresponds to a value, and the data structure is stored with key-value pairs.


To import the relevant preference of the system, the above diagram tells the method.

Changes in the code:
-Increase settingactivity
-Androidmanifest
Inform the activity, as well as the parent
-String.xml

Lauch Setting Activity Code Practice
待补充

Such modifications are available in both mainactivity and detailactivity.

Rest

3_23 Stay

Start

The essence of the third lesson is
Move Activity Listener
and a shared setting.

Add location perference related Xmlhard code style

Style with String.xml

Modify Settingactivity
3-243-25 只说到用户自己参考api:use user‘swhen fetching weather data from server
    • Load preferences XML layout in settingsactivity
    • Bind preference Summary to value for Loaction setting
中文解读:1)读取resource文件中的 perperence layout2)为loation 设置 绑定事件响应bindPreferenceSummaryToValue
Use shared Preferences Code practice

Principle Reference SDK website,
The main code reference is as follows:

In short, it is the value that we need from the preference key pair, which is then passed to the weather task as a parameter.

!! The real Refresh

The problem we're trying to solve is to get rid of the previous dummy data and use the real one.

The refresh of the data is done by the Updateweather function,
This function is in Forcastfragment.java.

We'll see where we call it.

onOptionsItemSelected    updateWeather
onStart    updateweather   

OK, mainly the above two, and also to the forcastfragment in the Oncreateview of false data are deleted

The test method is to enter the app and enter a new location to see if there are any data changes.

Temprature Unit Setting
3-283-29todo:

Keywords, review
To use a new preference subclass (one of the sharedpreference): Listpreference,

On the way, you can see the layout settings of List preference,
With regard to the role of Entryvalue and entries, I am not particularly clear now, seemingly the former constant, rather than the user is not visible.

todo 关于entryValue和entries的作用

The following code is designed to show the temperature unit options
The main is to add

settingActivity    onCreate        bindPreferenceSummaryToValue(getString(R.string.pref_units_key))

Complete the binding above.

The code that determines the temperature display format is

forecastFragment    formatHighLows(...)    {        If(转换为imperial == ture)            ....        else            doNothing        ...//最高温和最低温放一个字符串返回      }
!! Debugging Tips for Debug Breakpoint
3-30 详细介绍这里的内容

I'm not going to tell you, I was looking for the debug function for half a day.
To debug, not only to learn to play log, but also to step by step tracking.
Taking the preference function debugging here as an example, we will place breakpoints in the following two places in the setingactvitiy.

    • Line 59:preference.setsummary (Listpreference.get ...)
    • Line 63:
      Preference.setsummay (StringValue);

If the setting is successful, then each value set in the preference can be found at a breakpoint above.
And after the continue, it will be updated on the interface.

关于调试的几点扩展1.debugor relase exist2.条件断点3.支持多线程吗4.adb 模式如何调试5.可以加入framework 代码 进行调试吗6.可以支持jni代码的调试? c? 字节码?7.一本iso书的代码引入
Launch Implict Intent
3-31 直觉:站在巨人的肩膀上,引用其他app功能3-32 深入分析3-33 solution


Add a new setting item

Note that you should also update the string in Strings.xml Action_map


Above is the code that uses intent (the code is not complete), mainly
Join Openpreferredloactioninmap

todo 深入openPreferredLoactionInMap
Rest time-Third round

It's time to has a rest
Now proceed to 3-34
It's been two hours.

Intent resolution

Each app's actvitity has the following filters to handle map-related intent

<intent-filter>    <action = "android.intent.action.VIEW"/>    <data android:scheme ="geo"/></intent-filter>

In short, the filter

Share Intent Introduction

This is the most used intent by the developer.

    • Implementation form
      Action_send operation of Shareactionprovider

tips:使用ctrl+shiftwhenuse potplayer,定制播放窗口初始化大小,还有视频,详细见x_tips_player.jpg

Next, let's take a look at the wireframes, aided design

All implementations are carried out in the detail activity.


Above our todo list

Share Intent Code Practice

This is the content of course 3-36.
First, fill in a string, just in Strings.xml, Mark Action_share.

Then we add a new menu-related XML named Detailfragment.xml, as follows (this method is only valid for Android version 4.0 and above),

The third step, modify the content of Detailfragment,
Add Log_tag, and a token string,

Fourth step, this is the key, modify the Oncreateview,

每个activity都有自己的intent


-Get Intent
-Filter Extra_text
-Set value to the orignal intent "Extra_text"

Fifth Step, continue
The intent that we just ordered are in our own package.

One of the things to note is:
-Action_send type of activity
-a flag that does not save the state (the activity that is shared is not saved), Flag_actvity_clear_when_task_reset
, if you do not set it, you will have trouble exiting the activity

The 6th step is to enable the operation,
Add to the Deatailfragment constructor

setHasOptionsMenu(true);

This is the only sign that will call Oncreateoptionmenu (), which is the last step of the labor force.

The final step is to create our oncreateoptionmenu,

In short, this is our menu response function

Summarizing the content just now, this is the level I first understood (will be updated later)
-(step 1+2) prepare the layout.
-(step3+4+5) Initialize Intent
-(step 6/7) Menu response function

Nap

The first time in the brain, all kinds of intent run, rest a while

Broad intent
    • The system sends information, such as charging, which is achieved through the Sendbroadcast method.
3-37 原理介绍3-38 代码框架+ 接受的两种实现

This course of dry goods, but also more, mainly is how appropriate to accept the broadcast content.

First put on a classic figure,

The following four diagrams, respectively, from the maniest mode and the dynamic way of introducing the implementation of the receiver code


Here we have just learned the principle of radio reception, applied to the reception of charging events,

Milestone time
    • How to create new activity
    • The relation with activities
      • Structure level
      • Navigation (Parent child)
    • How to use the INTENT

The exciting activity life cycle is in the next lesson.
-Data preservation
-Database
-ContentProvider

Other, Introduction to Android Play (high quality/stable)

Section:

1.5 hours in the evening

Other

What is Frament?

Open source OJ P.A.T app
Middle:dan
Raydo,
Catherine

Location: Shanghai University Baoshan Campus C District 1 Floor a classroom

Udacity Android Learning Note: Lesson 3

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.