Bassti schrieb:
> Vielleicht kann noch jemand helfen
Vermutlich ja, das hat jetzt aber doch überhaupt nix mehr mit der
Ursprungsfrage zu tun! Also die Dinger in den Spitzenklammern nennen
sich Generics, die musst du dann schon passend zu deinen "Wünschen"
definieren, die API sagt dazu:
1 | AsyncTask<Params, Progress, Result>
|
2 |
|
3 | The three types used by an asynchronous task are the following:
|
4 | Params, the type of the parameters sent to the task upon execution.
|
5 | Progress, the type of the progress units published during the background computation.
|
6 | Result, the type of the result of the background computation.
|
So, das heisst, beim ersten kannst du (vermutlich?) String lassen falls
deine Eingabeparameter Strings sind. Beim zweiten schreibst du dann byte
hin, onProgressUpdate erlaubt automatisch ein array des zweiten Typs,
wenn du arrays von bytearrays hast dann eben byte[].
Da du scheinbar nix zurückgibst als Ergebnis (wieso nicht siehe
vorherige Anmerkung) kannst du dor einfach Void schreiben, also würde
deine Definition so aussehen:
1 | public class connectTask extends AsyncTask<String, byte, Void> {
|
2 | protected Void doInBackground(URL... urls) {
|
3 | //we create a TCPClient object and
|
4 | mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() {
|
5 |
|
6 | //here the messageReceived method is implemented
|
7 | public void messageReceived(byte[] message) {
|
8 | //this method calls the onProgressUpdate
|
9 | publishProgress(message);
|
10 | }
|
11 | });
|
12 |
|
13 | mTcpClient.run();
|
14 | return null;
|
15 | }
|
16 |
|
17 | protected void onProgressUpdate(byte[]... values) {
|
18 | // tu was damit...
|
19 | }
|
20 |
|
21 | protected void onPostExecute(Void result) {
|
22 | //do nothing here...
|
23 | }
|
24 | }
|
Wie gesagt, wenn du wirklich im Hintergrund was machen willst wäre es
vermutlich mit onPostExecute besser, es sei den deine bytes trudeln
wirklich Stückweise rein und du willst die auch stückweise verarbeiten.
Allgemein: Schau in die API! Da steht alles drin und meist auch ein
Codeschnipsel, Beispiele aus dem Netz zeigen oft unvollständig nur das
was gerade so nötig ist.