인텐트


Intent의 첫번째 매개변수는 호출하는 액티비티를 나타내고, 두번째 매개변수에는 호출할 액티비티를 나타냅니다.

  그리고 Intent하는 두 액티비티는 모두 manifest에 등록되어 있어야한다!!!!

1
2
3
 Intent intent = new Intent(this, MainActivity.class);
 startActivity(intent);
 finish();
cs



인텐트(Intent)는 컴포넌트에 액션, 데이터 등을 전달하는 메시지 객체이다. 인텐트 객체의 구성 요소는 다음과 같다.

 

Action (액션): 수행할 액션 이름(ACTION_DIAL)

Data (데이터): 수행할 데이터의 URI(tel:)

Category (카테고리): 수행할 액션에 대한 추가적인 정보

Type (타입): 수행할 인텐트 데이터의 명시적인 타입(MIME 타입) (video/mpeg)

Component name (컴포넌트 이름): 대상 컴포넌트의 완전한 클래스 이름

Extras (추가 정보): 인텐트를 다루는 컴포넌트에 추가적으로 전달할 한 쌍의 키 /

 

컴포넌트 활성화 시점

컴포넌트

활성화 시점

Activity

인텐트에 의해 활성화

Service

인텐트에 의해 활성화

Broadcast Receiver

인텐트에 의해 활성화

Content provider

ContentResolver에 의해 활성화

 

컴포넌트 활성화

컴포넌트

활성화

Activity

Context.startActivity()

Activity.startActivityForResult()에 인텐트 객체를 전달해서 활성화

Service

Context.startService()에 인텐트 객체를 전달해서 활성화 
안드로이드는 인텐트 객체를 ServiceonStart() 메소드에 전달

Broadcast Receiver

Context.sendBroadcast()

Context.sendOrderedBroadcast()

Context.sendStickyBroadcast()에 인텐트 객체를 전달해서 활성화



인텐트 필터

인텐트 필터(Intent Filter)는 특정 인텐트를 받을지 말지를 정의하는 역할을 수행하며, 이를 통해 컴포넌트의 특징이 정해진다. 예를 들어, 인텐트 필터에 android.intent.action.MAIN을 선언하고 다음에 android.intent.category.HOME을 선언하면, 해당 컴포넌트는 홈 애플리케이션이 되어 디바이스가 시작될 때 자동으로 시작될 수 있는 애플리케이션이 된다. 인텐트 필터를 구성하는 요소는 인텐트에 작성할 수 있는 요소들과 동일하다.

- 앱 컴포넌트는 인텐트 필터를 가질 수 있고, 안드로이드는 인텐트 필터를 이용하여 어떤 앱 컴포넌트에 암시적 인텐트를 전달할지를 결정.


- 명시적 인텐트에는 클래스 이름이 설정되어 있어 무엇을 실행할지가 명확함.

-  - 묵시적 인텐트는 클래스 이름 대신 액션 이름이 설정됨.

         (액션 이름만으로는 어떤 앱 컴포넌트를 실행할지가 명확하지 않다.)

 


새로운 액티비티가 뜨면, HOME화면으로 이동하는 예제와 설명


1
2
3
4
5
6
7
8
9
10
 private void fobidden_activity() {
  Intent intent = new Intent();
  intent.setAction("android.intent.action.MAIN");
  intent.addCategory("android.intent.category.HOME");
  intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 
   | Intent.FLAG_ACTIVITY_FORWARD_RESULT
      | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP
      | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
  startActivity(intent);
 }
cs

setAction

Added in API level 1
Intent setAction (String action)

Set the general action to be performed.

Parameters
actionString: An action name, such as ACTION_VIEW. Application-specific actions should be prefixed with the vendor's package name.
Returns
IntentReturns the same Intent object, for chaining multiple calls into a single statement.


ACTION_MAIN

Added in API level 1
String ACTION_MAIN

Activity Action: Start as a main entry point, does not expect to receive data.

Input: nothing

Output: nothing

Constant Value: "android.intent.action.MAIN"



addCategory

Added in API level 1
Intent addCategory (String category)

Add a new category to the intent. Categories provide additional detail about the action the intent performs. When resolving an intent, only activities that provide all of the requested categories will be used.

Parameters
categoryString: The desired category. This can be either one of the predefined Intent categories, or a custom category in your own namespace.
Returns
IntentReturns the same Intent object, for chaining multiple calls into a single statement.


addFlags

Added in API level 1
Intent addFlags (int flags)

Add additional flags to the intent (or with existing flags value).

Parameters
flagsint: The new flags to set.
Returns
IntentReturns the same Intent object, for chaining multiple calls into a single statement.

CATEGORY_HOME

Added in API level 1
String CATEGORY_HOME

This is the home activity, that is the first activity that is displayed when the device boots.

Constant Value: "android.intent.category.HOME"



intFLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

If set, the new activity is not kept in the list of recently launched activities.

intFLAG_ACTIVITY_FORWARD_RESULT

If set and this intent is being used to launch a new activity from an existing one, then the reply target of the existing activity will be transfered to the new activity.

intFLAG_ACTIVITY_NEW_TASK

If set, this activity will become the start of a new task on this history stack.

intFLAG_ACTIVITY_PREVIOUS_IS_TOP

If set and this intent is being used to launch a new activity from an existing one, the current activity will not be counted as the top activity for deciding whether the new intent should be delivered to the top instead of starting a new on

intFLAG_ACTIVITY_RESET_TASK_IF_NEEDED

If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task.


출처 : https://developer.android.com/reference/android/content

'Programming > Android' 카테고리의 다른 글

AsyncTask  (0) 2016.08.26
AccessibilityService  (0) 2016.08.26
어플 패키지명  (0) 2016.08.25
ProgressDialog 와 Toast  (0) 2016.08.25
HttpURLConnection  (0) 2016.08.25

kakao 패키지명 - com.kakao.talk

카메라 패키지명 - com.android.camera

갤러리 패키지명 -  com.android.gallery

'Programming > Android' 카테고리의 다른 글

AccessibilityService  (0) 2016.08.26
Intent와 Intent Filter  (0) 2016.08.26
ProgressDialog 와 Toast  (0) 2016.08.25
HttpURLConnection  (0) 2016.08.25
SharedPreferences  (0) 2016.08.24

이번 여름방학에는 청각장애인을 위한 아기 모니터링 시스템을 만들어보았다.

사실 말이 청각장애인을 위한 것이지, 사실 일반 모니터링 시스템과 별반 다를게 없다.

청각장애인을 위해서 내가 할수있는 일은 무엇일까? 다른 장애인분들을 위해서 내가 할수있는 것은 무엇일까?

IT의 혜택을 받지 못하는 분들을 위해서 내가 할수있는것은 무엇일까?

내 실력탓이 크겟지만 이번 프로젝트를 통해서 뭔가 획기적인게 나올줄 알았는데, 생각보다 너무 무난하게 나온것 같다

그래도 이 프로젝트 덕분에 안드로이드 프로그래밍, Node.js, 아두이노를 조작해 보아서 좋은 경험이 되었다. 

또 서로 통신을 구현하는게 정말 큰 경험이였던것 같다.

하지만 아쉬운점은 httppost httpclient를 쓰지 못하고 urlconectino을 사용했다는것... 이부분이 정말 아쉬운 부분이였던것 같다.

또 생각했던 부분까지 잘 되지 않아서 그것도 좀 아쉽다. 뭐 그부분이야 이번학기 캡스톤디자인때 구현해서 적용시키면 되겠지만..


그리고 요즘 궁금한건 어떻게 컴퓨터는 이 그림이 어떤 그림인지 아는걸까?

'Think' 카테고리의 다른 글

참을수 없는 교회의 가벼움이라...  (0) 2016.08.28
터널  (0) 2016.08.28
새로운 아이디어! - 추가  (0) 2016.08.27
에듀테크...  (0) 2016.08.27
새로운 아이디어!  (0) 2016.08.26

1. ProgressDialog

setMessage로 세팅하고,

show로 보여주고 dismiss로 안보여주고...


1
2
3
4
5
6
7
8
9
10
static ProgressDialog dialog;
 
dialog = new ProgressDialog(this);
        dialog.setMessage(string);
        dialog.show();
    }
)
 
dialog.dismiss();
   
cs


2. Toast

Toast는 첫번째 매개변수에 Context를 넣어야하는데 GetApplicationContext()를 사용하여 해당 Context를 받아 오도록하자

Toast.LENGTH_SHORT와 LONG가 있는데 취향에 맞춰 골라 쓰세요.


1
2
 Toast.makeText(getApplicationContext(), "Test",Toast.LENGTH_SHORT).show();
 
cs


'Programming > Android' 카테고리의 다른 글

Intent와 Intent Filter  (0) 2016.08.26
어플 패키지명  (0) 2016.08.25
HttpURLConnection  (0) 2016.08.25
SharedPreferences  (0) 2016.08.24
Context  (0) 2016.08.24

 HttpURLConnection이 Httppost와 다른 이유는 전송 데이터를 URL에 넣어 전송하느냐 body에 넣어 전송하느냐이다.

후자가 데이터를 감추기에 더 좋을꺼 같긴하다..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

try {
 
                URL obj = new URL(url+"?"+paramString.toString());
                HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
 
                conn.setReadTimeout(5000);
                conn.setConnectTimeout(5000);
                conn.setDefaultUseCaches(false);
                conn.setRequestMethod("POST");
                conn.setDoInput(true);
                conn.setDoOutput(true);
 
                PrintWriter pw = new PrintWriter(new OutputStreamWriter(conn.getOutputStream()));
                pw.write(paramString);
                pw.flush();
                pw.close();
                int retCode = conn.getResponseCode();
 
                if (retCode == HttpURLConnection.HTTP_OK) {
                    InputStream is = conn.getInputStream();
                    BufferedReader br = new BufferedReader(new InputStreamReader(is)."UTF-8");
                    String line;
                    StringBuffer response = new StringBuffer();
                    while((line = br.readLine()) != null){
                        response.append(line);
                    }
                    br.close();
                    Log.d(TAG,"responvalue: "+response.toString());
                    return response.toString();
                }else{
                    Log.d(TAG,"error code is " + retCode);
                }
 
            } catch (Exception e) {
                e.printStackTrace();
            }
cs

22번 라인에 "UTF-8"을 추가하면 한글깨짐현상을 막을수 있다.



'Programming > Android' 카테고리의 다른 글

어플 패키지명  (0) 2016.08.25
ProgressDialog 와 Toast  (0) 2016.08.25
SharedPreferences  (0) 2016.08.24
Context  (0) 2016.08.24
Activity 생명주기  (0) 2016.08.24

아두이노를 사용하여 시리얼 통신을할때 문자열을 합쳐야 하는 경우가 생긴다

이때는 concat(string str); 이나 String변수끼리 + 연산을 하면되는데

사실 뭘하든지 결과는 같다.


1
2
3
4
5
6
String str1 = "안녕";
String str2 = "하세요";
 
println(str1.concat(str2));
 
println(str1+str2);
cs


같은 값이 나오는 걸 확인할 수 있을 것이다.

(2016년 여름방학 프로젝트 하는 중에 가장 애를 많이 썩인 부분이다....)

출처 : https://www.npmjs.com/package/serialport


명령어 : npm install serialport(@version) --save


serialport를 다운받는 가장 좋은 방법은 https://github.com/nodesource/distributions#installation-instructions 를 참고하는 것이다.


라즈베리파이에서 apt-get으로 다운 받은 node.js 는 0.10.x 버전이기 때문에 serialport@1.7.4를 다운 받아야한다.


그리고 시리얼 통신시 중요한 parser이다.

아두이노에서 서버로 여러개의 센서 데이터 값을 받아올때 값이 같이안오고 따로전송이 된다.

이를 막기위한 방법으로 parser를 사용하는 방법이 있더라.

1
2
3
4
5
var SerialPort = require('serialport');
 
var port = new SerialPort('/dev/tty-usbserial1', {
  parser: SerialPort.parsers.readline('\n')
});
cs


서버에서 클라이언크단으로 데이터를 전송하는 법은 이런식이다.

1
2
3
4
5
function writeAndDrain (data, callback) {
  sp.write(data, function () {
    sp.drain(callback);
  });
}
cs


'Programming > Node.JS' 카테고리의 다른 글

Event개념 이해  (0) 2016.09.03
기본 내장 모듈  (0) 2016.09.03
전역 객체에 대하여  (0) 2016.09.03
node.js 특징  (0) 2016.09.03
Node.js 에서 JSON 사용하기  (0) 2016.08.27

시작은 이걸로

후렴은 이걸로


'Guitar' 카테고리의 다른 글

빛 되신 주  (0) 2016.08.24

+ Recent posts