android

[Android] AsycTask사용하기

포카리s 2016. 2. 26. 20:35
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// input your code herepackage com.sjw.js.httpconex;
 
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
 
import java.util.HashMap;
 
public class MainActivity extends AppCompatActivity {
 
    private TextView textView;
    BackgroundTask aa;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        textView = (TextView)findViewById(R.id.textView);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
            }
        });
    }
 
    class BackgroundTask extends AsyncTask<HashMap<StringString>StringString >{
 
            private String url;
            private HashMap<StringString> param;
 
            public BackgroundTask(String siteUrl, HashMap<StringString> parameters){
                this.param = new HashMap<StringString>();
                this.url = siteUrl;
                this.param = parameters;
            }
 
            /**
             * Thread를 시작하기 전에 호출하는 함수
             */
            @Override
            protected void onPreExecute(){
                super.onPreExecute();
            }
 
 
        /**
         * Thread의 주요 작업을 처리하는 함수
         * Thread를 실행하기 위해 execute(*)에서 전달한 값을 인자로 받습니다.
         */
        @Override
        protected String doInBackground(HashMap<StringString>... params){
            HttpUrlConnection ttt = new HttpUrlConnection();
            String aa = ttt.performPostCall(url, param);
            return aa;
        }
 
 
        /**
         * doInBackground(*)에서 호출되어 주로 UI관련 작업을 하는 함수
         */
        @Override
        protected void onProgressUpdate(String... progress){
 
        }
 
 
        /**
         * Thread를 처리한 후에 호출되는 함수
         * doInBackground(*)의 리턴값을 인자로 받습니다.
         */
        @Override
        protected void onPostExecute(String result){
            super.onPostExecute(result);
 
        }
    }
 
}
 

cs