Giriş
Şu satırı dahil ederiz.
Şöyle yaparız.
AssetManager sınıfını döndürü. Şöyle yaparız.
Genellikle ekran bileşenlerini güncellemek için kullanılır.
Örnek
Şöyle yaparız.
Şöyle yaparız.
Context.startActivity metodu yazısına taşıdım.
startService metodu
Şöyle yaparız.
Şöyle yaparız
Şu satırı dahil ederiz.
import android.content.Context;java.lang.Object
  ↳ android.content.Context
      ↳ android.content.ContextWrapper
          ↳ android.view.ContextThemeWrapper
              ↳ android.app.Activityjava.lang.Object
↳   android.content.Context
   ↳    android.content.ContextWrapper
       ↳    android.app.ApplicationŞöyle yaparız.
Context ctx = this.getApplicationContext();AssetManager sınıfını döndürü. Şöyle yaparız.
AssetManager am = context.getAssets();
getContentResolver metodu
ContentResolver nesnesi döndürür. Şöyle yaparız.
DexFile ile kullanabiliriz. Şöyle yaparız.
PackageManager nesnesi döndürür. Şöyle yaparız.
Şöyle yaparız.
SharedPreferences nesnesi döndürür. Şöyle yaparız.
ActivityManager nesnesi döner. Şöyle yaparız.
Şöyle yaparız.ContentResolver nesnesi döndürür. Şöyle yaparız.
ContentResolver resolver = context.getContentResolver();DexFile ile kullanabiliriz. Şöyle yaparız.
DexFile df = new DexFile(context.getPackageCodePath());PackageManager nesnesi döndürür. Şöyle yaparız.
PackageManager pm = context.getPackageManager();Şöyle yaparız.
String packageName = context.getPackageName();SharedPreferences nesnesi döndürür. Şöyle yaparız.
SharedPreferences sp = context.getSharedPreferences("...", Context.MODE_PRIVATE);ActivityManager nesnesi döner. Şöyle yaparız.
ActivityManager cm = (ActivityManager)context.
  getSystemService(Context.ACTIVITY_SERVICE);
AlarmManager nesnesi döner. Şöyle yaparız.
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);ClipboardManager cm = (ClipboardManager)context.
  getSystemService(Context.CLIPBOARD_SERVICE);ConnectivityManager cm = (ConnectivityManager)context.
  getSystemService(Context.CONNECTIVITY_SERVICE);DownloadManager dm = (DownloadManager)context.
  getSystemService(Context.DOWNLOAD_SERVICE);LayoutInflater inflater = (LayoutInflater)context.
  getSystemService(Context.LAYOUT_INFLATER_SERVICE);InputMethodManager lm = (InputMethodManager) context
  .getSystemService(Context.INPUT_METHOD_SERVICE);LocationManager lm = (LocationManager) context
  .getSystemService(Context.LOCATION_SERVICE);NotificationManager nm = (NotificationManager) context
  .getSystemService(Context.NOTIFICATION_SERVICE);PowerManager pm = (PowerManager) context
  .getSystemService(Context.POWER_SERVICE);
TelephonyManager nesnesi döner. Şöyle yaparız.
TelephonyManager tm = (TelephonyManager) context
  .getSystemService(Context.TELEPHONY_SERVICE);WifiManager wm = (WifiManager) context.
  getSystemService(Context.WIFI_SERVICE);WindowManager wm = (WindowManager) context.
  getSystemService(Context.WINDOW_SERVICE);
FileInputStream fis = null;
try {
  fis = context.openFileInput(...);
} catch (FileNotFoundException e) {
  ...
}Genellikle ekran bileşenlerini güncellemek için kullanılır.
Örnek
Şöyle yaparız.
context.runOnUiThread(new Runnable {
  public void run() {
    // your UI stuff
  }
})Şöyle yaparız.
runOnUiThread(new Runnable() {
  status1.setText("Recording");
});
Örnek
Şöyle yaparız.
Şöyle yaparız.
public void setMessage(String message) {
  if (dialog != null && dialog.isShowing()) {
    ((Activity) context).runOnUiThread(new Runnable() {
      @Override
      public void run() {
        dialog.setMessage(message);
      }
    });
  }
}
Örnek
Şöyle yaparız.context.runOnUIThread(new Runnable() {
  public void run(){
    Toast.showToast("your message here")
  }
});Context.startActivity metodu yazısına taşıdım.
startService metodu
Şöyle yaparız.
Intent i = ...;
ComponentName service = context.startService (i);Şöyle yaparız
Intent i = ...;
context.stopService (i); 
Hiç yorum yok:
Yorum Gönder