Created
November 24, 2012 08:04
-
-
Save jcarlos7121/4138839 to your computer and use it in GitHub Desktop.
Interaccion Con WorkerService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package directorio.actividades.test; | |
| import java.io.File; | |
| import android.os.Bundle; | |
| import android.os.Environment; | |
| import android.os.Handler; | |
| import android.os.IBinder; | |
| import android.os.Message; | |
| import android.os.Messenger; | |
| import android.app.Activity; | |
| import android.content.ComponentName; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.ServiceConnection; | |
| import android.util.Log; | |
| import android.view.Menu; | |
| import android.widget.Toast; | |
| public class MainActivity extends Activity { | |
| Messenger messenger = null; | |
| String holo = "Aun no termina"; | |
| private Handler handler = new Handler() { | |
| public void handleMessage(Message message) { | |
| Object path = message.obj; | |
| if (message.arg1 == RESULT_OK && path != null) { | |
| holo = "Termino bato lodo"; | |
| Toast.makeText(MainActivity.this, | |
| "Downloaded" + path.toString(), Toast.LENGTH_LONG) | |
| .show(); | |
| } else { | |
| Toast.makeText(MainActivity.this, "Download failed.", | |
| Toast.LENGTH_LONG).show(); | |
| } | |
| }; | |
| }; | |
| private ServiceConnection conn = new ServiceConnection() { | |
| @Override | |
| public void onServiceConnected(ComponentName className, IBinder binder) { | |
| messenger = new Messenger(binder); | |
| } | |
| @Override | |
| public void onServiceDisconnected(ComponentName className) { | |
| messenger = null; | |
| } | |
| }; | |
| @Override | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.main); | |
| Intent intent = new Intent(this, WorkService.class); | |
| // Create a new Messenger for the communication back | |
| Messenger messenger = new Messenger(handler); | |
| intent.putExtra("MESSENGER", messenger); | |
| startService(intent); | |
| } | |
| @Override | |
| protected void onResume() { | |
| // TODO Auto-generated method stub | |
| super.onResume(); | |
| File SDCardRoot = Environment.getExternalStorageDirectory(); | |
| File file = new File(SDCardRoot, "Volta.db"); | |
| if(file.exists() && holo == "Termino bato lodo"){ | |
| Toast.makeText(this, "Existe bato loco : O", Toast.LENGTH_SHORT).show(); | |
| }else{ | |
| Toast.makeText(this, "Aun no termina bato loco... : O", Toast.LENGTH_SHORT).show(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment