이미지를 표시하고 싶습니다. 여기서 서비스 작업을 수행하고 결과를 UI에 표시해야합니다. 나는 requirment 당 async 작업을 사용하고 싶지 않다. 진행하고 이미지를 표시하는 방법을 모르겠습니다. 도와주세요. 내 코드가android에서 서비스를 사용하여 이미지를 표시하는 방법
은 다음과 같습니다
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?
}
}
만약 startActivity()로 방송에게 의도를 보낼에
그리고 당신의 서비스에
, 귀하의 이미지 – pskink미안 해요 you.how 내가 imageview에 표시 할 수 있습니까? 선언하고 어디에서 얻을 수 있습니까? @pskink – Shadow
서비스에서 메인 스레드를 업데이트하는 방법을 확인하면 문제가 해결 될 것입니다. –