1 package android.os; 2 3 import android.app.Service; 4 import android.content.Intent; 5 import java.io.File; 6 import java.io.IOException; 7 8 /** Service in separate process available for calling over binder. */ 9 public class SomeService extends Service { 10 11 private File mTempFile; 12 13 @Override onCreate()14 public void onCreate() { 15 super.onCreate(); 16 try { 17 mTempFile = File.createTempFile("foo", "bar"); 18 } catch (IOException e) { 19 throw new RuntimeException(e); 20 } 21 } 22 23 private final ISomeService.Stub mBinder = 24 new ISomeService.Stub() { 25 public void readDisk(int times) { 26 for (int i = 0; i < times; i++) { 27 mTempFile.exists(); 28 } 29 } 30 }; 31 32 @Override onBind(Intent intent)33 public IBinder onBind(Intent intent) { 34 return mBinder; 35 } 36 37 @Override onDestroy()38 public void onDestroy() { 39 super.onDestroy(); 40 mTempFile.delete(); 41 } 42 } 43