Skip to content

Commit 7ddd7bd

Browse files
Update README.md
1 parent 99e3670 commit 7ddd7bd

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ We have Two classes FetchData and PutData. Import the Library to your file first
2727
### Read Data From a URL - FetchData.class
2828
You need to use Handler and post a Runnable. Inside the run method add the code for FetchData.
2929

30-
* Creating the object for FetchData.
30+
* Creating the object for FetchData, pass the URL as argument.
3131
```
3232
FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php");
3333
```
@@ -63,6 +63,40 @@ handler.post(new Runnable() {
6363
```
6464

6565
### Write data with POST and GET methods - PutData.class
66+
You need to use Handler and post a Runnable. Inside the run method add the code for PutData.
67+
68+
* First we need to create to arrays, one for field name of the parameter and another for the data. Make sure the order is correct.
69+
```
70+
String[] param = new String[2];
71+
param[0] = "param-1";
72+
param[1] = "param-2";
73+
String[] data = new String[2];
74+
data[0] = "data-1";
75+
data[1] = "data-2";
76+
```
77+
* PHP representation, The post array will look like,
78+
```
79+
$_POST['param-1'] = "data-1";
80+
$_POST['param-2'] = "data-2";
81+
```
82+
83+
* Creating the object for PutData, pass the URL, method, field, data as arguments. The method can be POST and also GET.
84+
```
85+
PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data);
86+
```
87+
* Calling startFetch() for starting the process, it returns a boolean value.
88+
```
89+
putData.startFetch();
90+
```
91+
* To know when the process is completes use onComplete() which returns a boolean value.
92+
```
93+
putData.onComplete();
94+
```
95+
* If the process is complete, use the getResult() to get the result value.
96+
```
97+
putData.getResult();
98+
```
99+
* Full implimentation with Handler. You can also add a progress bar at the commended regions.
66100
```
67101
//Start ProgressBar first (Set visibility VISIBLE)
68102
Handler handler = new Handler();
@@ -78,7 +112,7 @@ handler.post(new Runnable() {
78112
String[] data = new String[2];
79113
data[0] = "data-1";
80114
data[1] = "data-2";
81-
PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "GET", param, data);
115+
PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data);
82116
if (putData.startFetch()) {
83117
if (putData.onComplete()) {
84118
String result = putData.getResult();

0 commit comments

Comments
 (0)