bonjour,
je suis entrain de développer une application permettant de faire un backup mobile sur un PC et ce dans le cadre d'un projet de diplôme. le souci est que j'aimerai faire fonctionner un thread dans mon application android en arrière plan. Or une fois ce thread se trouve lancer, c'est l'application android elle même qui s'exécute en arrière plan. En gros l'application reste bloquée sur le thread.
Ce thread a comme tache d'envoyer une liste de fichiers sur un serveur (PC). Et dans mon application j'aimerai pouvoir afficher grâce a un View de type ProgressBar l'état d'avancement du transfert.
voici la partie du code de mon application android:
merci d'avance!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public void BackupMediaMenu(View Button) { pictureRadio = (RadioButton) findViewById(R.id.pictureRadioBtn); audioRadio = (RadioButton) findViewById(R.id.audioRadioBtn); videoRadio = (RadioButton) findViewById(R.id.videoRadioBtn); SendList sendMList = new SendList(user.userCommand, PICTURE_VIDEO_PATH); Thread thread = new Thread(sendMList); try { if (pictureRadio.isChecked()) { sendMList.setMediaIndex(0); } if (videoRadio.isChecked()) { sendMList.setMediaIndex(1); } if (audioRadio.isChecked()) { sendMList.setMediaIndex(2); } thread.start(); transfert(); } catch (Exception e) { e.printStackTrace(); } } public void transfert() { setContentView(R.layout.progress); ProgressBar pb = (ProgressBar)findViewById(R.id.progressBar2); pb.setMax(nbFiles); int valProg = 0; while (valProg<=nbFiles){ if (user.userCommand.getFileFlagTransfert()){ pb.setProgress(valProg++); } } }
Partager