我想展示图片。我需要在服务中执行操作并在 UI 中显示结果。根据要求,我不想使用异步任务。我不知道如何继续并显示图片,请帮助我。
我的代码如下:
我的代码如下:
public class Service_Photo extends Service {
public Service_Photo() {
}
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(this, "The new Service was Created", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
// For time consuming an long tasks you can launch a new thread here...
Toast.makeText(this, " Service Started", Toast.LENGTH_LONG).show();
updateImages();
}
private void updateImages()
{
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "am/a.jpg";
File f = new File(baseDir + File.separator + fileName);
if(f.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
// img = (ImageView)findViewById(R.id.image);
// img.setImageBitmap(myBitmap);
Toast.makeText(getApplicationContext(), "Hello"+myBitmap.toString(), Toast.LENGTH_SHORT)
.show();
}
}
@Override
public void onDestroy() {
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
public class ImageDisplay extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//how to display the operation performed in service and display in image from service?
}
}