Skip to content

Commit

Permalink
GitBook: [master] 12 pages and 30 assets modified
Browse files Browse the repository at this point in the history
  • Loading branch information
yemreak authored and gitbook-bot committed Nov 23, 2019
1 parent 86385a3 commit a0d8e29
Show file tree
Hide file tree
Showing 42 changed files with 267 additions and 35 deletions.
Binary file modified .gitbook/assets/image (10).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (11).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (12).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (13).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (14).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (15).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (16).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (17).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (18).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (19).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (2).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (20).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (21).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (22).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (23).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (24).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (25).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (26).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (27).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/image (28).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/image (29).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (3).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/image (30).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/image (31).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (4).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .gitbook/assets/image (5).png
Binary file modified .gitbook/assets/image (6).png
Binary file modified .gitbook/assets/image (7).png
Binary file modified .gitbook/assets/image (8).png
Binary file modified .gitbook/assets/image (9).png
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ Tam olarak hangi alanların değiştiğini merak ediyorsan, alttaki linkten GitH

**The** [**MIT License**](https://choosealicense.com/licenses/mit/) **© Yunus Emre Ak**

![](.gitbook/assets/image%20%282%29.png)
![](.gitbook/assets/image%20%283%29.png)

1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [🌄 Arkaplan'da Çalışma](temel-kavramlar/arkaplanda-calisma/README.md)
* [💫 AsyncTask ve AsyncTaskLoader](temel-kavramlar/arkaplanda-calisma/asynctask-ve-asynctaskloader.md)
* [🌠 MultiThreading](temel-kavramlar/arkaplanda-calisma/multithreading.md)
* [🌞 Foreground Service](temel-kavramlar/arkaplanda-calisma/foreground-service.md)
* [🌠 Android Servisleri](temel-kavramlar/arkaplanda-calisma/android-servisleri.md)

## Faydalı Bilgiler
Expand Down
2 changes: 1 addition & 1 deletion faydali-bilgiler/activity-oernekleri.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ startActivity(intent)

{% tabs %}
{% tab title="⭐ Örnek" %}
![](../.gitbook/assets/image%20%2827%29.png)
![](../.gitbook/assets/image%20%2831%29.png)
{% endtab %}

{% tab title="Manifest" %}
Expand Down
8 changes: 4 additions & 4 deletions faydali-bilgiler/proje-islemleri.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* Son olarak; Manifestimize girip "package name"i güncelliyoruz.
* Artık başarıyla "package name"i güncellemiş olduk. Emin olmak için projenizi Build etmeyi unutmayın :\)

![](../.gitbook/assets/image%20%2817%29.png)
![](../.gitbook/assets/image%20%2821%29.png)

![](../.gitbook/assets/image%20%2818%29.png)

![](../.gitbook/assets/image%20%2813%29.png)
![](../.gitbook/assets/image%20%2822%29.png)

![](../.gitbook/assets/image%20%2816%29.png)

![](../.gitbook/assets/image%20%2820%29.png)

2 changes: 1 addition & 1 deletion temel-kavramlar/activity-ve-intentler.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

### Back navigation, tasks, and the back stack

![](../.gitbook/assets/image%20%284%29.png)
![](../.gitbook/assets/image%20%285%29.png)

### Implement Up navigation with a parent Activity

Expand Down
2 changes: 1 addition & 1 deletion temel-kavramlar/activity-yasam-doenguesue.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 🔄 Activity Yaşam Döngüsü

![](../.gitbook/assets/image%20%2825%29.png)
![](../.gitbook/assets/image%20%2829%29.png)

## 🧱 Metot Prototipi

Expand Down
4 changes: 2 additions & 2 deletions temel-kavramlar/androidde-animasyonlar.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{% tabs %}
{% tab title="⭐ Görsel" %}
![](../.gitbook/assets/image%20%289%29.png)
![](../.gitbook/assets/image%20%2812%29.png)
{% endtab %}

{% tab title="📜 XML Kodları" %}
Expand Down Expand Up @@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() {

{% tabs %}
{% tab title="⭐ Görsel" %}
![](../.gitbook/assets/image%20%2810%29.png)
![](../.gitbook/assets/image%20%2813%29.png)
{% endtab %}

{% tab title="📜 XML Kodları" %}
Expand Down
13 changes: 0 additions & 13 deletions temel-kavramlar/arkaplanda-calisma/android-servisleri.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,5 @@
* 🌑 Cihaz uyku moduna girdiğinde arka plan işlemleri aksamaya başlar, bundan dolayı [WakeLock](https://developer.android.com/training/scheduling/wakelock#java) özelliğinin aktif olması gerekir
* ⏳ Uzun süreli işlemler için hızı ve verimliliği artırma adına [multi-threading](https://developer.android.com/training/multiple-threads/) yapısı tercih edilmelidir

## 🌞 Foreground Services

Kullanıcının bildirim veya arayüz ile haberi olan arkaplan görevleridir

* Önceli servislerdir ve öncelik seviyesi bildirilmelidir
* Kullanıcıya [kaldırılamayan bir bildirim](https://developer.android.com/guide/topics/ui/notifiers/notifications.html#foreground-service) gösterilmesi zorunludur
* Kullanıcının arkaplan işlemlerinden haberdar olması amaçlanır
* Servisin çalıştırılması için [`FOREGROUND_SERVICE`](https://developer.android.com/reference/android/Manifest.permission.html#FOREGROUND_SERVICE) iznine ihtiyaç duyulur
* Android'in [izin isteme hiyerarşisine](https://developer.android.com/guide/topics/permissions/overview) uygun ilerler
* İzin alınmadığı taktirde [`SecurityException`](https://developer.android.com/reference/java/lang/SecurityException.html) hatası verir

{% hint style="info" %}
🧙‍♂️ Android dokümanında [Running a service in the foreground](https://developer.android.com/guide/components/services#Foreground) alanında işlenmektedir
{% endhint %}

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Android'teki tüm görüntü işlemlerinin yapıldı alandır.
* UI Thread sadece görsel işlemler için kullanılmalıdır
* Tüm işlemler 16ms'den kısa bir sürede tamamlanmalıdır

![](../../.gitbook/assets/image%20%2820%29.png)
![](../../.gitbook/assets/image%20%2824%29.png)

{% hint style="danger" %}
Yaklaşık olarak 5s'den uzun süren işlemler "[application not responding](http://developer.android.com/guide/practices/responsiveness.html)" \(ANR\) diyaloğunu oluşturur ve kullanıcı bunu görmesi durumunda uygulamayı kapatıp, siler 😥
Expand All @@ -50,9 +50,9 @@ Verilen işlemi arkaplanda, sistemi bloklamadan tamamlar.

{% tabs %}
{% tab title="🎈 Kullanım" %}
![](../../.gitbook/assets/image%20%2814%29.png)
![](../../.gitbook/assets/image%20%2818%29.png)

![](../../.gitbook/assets/image%20%2811%29.png)
![](../../.gitbook/assets/image%20%2814%29.png)

| 💠 Metot | 📜 Açıklama |
| :--- | :--- |
Expand All @@ -75,7 +75,7 @@ public class MyAsyncTask extends AsyncTask <String, Void, Bitmap>{}
* `Void` yapısı, `publishProgress` ve `onProgressUpdate` metotlarının kullanılmayacağını belirtir
* `Bitmap` tipi de, `onPostExecute` ile aktarılan işlem sonucunun tipini belirtir

![](../../.gitbook/assets/image%20%287%29.png)
![](../../.gitbook/assets/image%20%288%29.png)

{% hint style="warning" %}
Son iki parametre \(`Void` ve `Bitmap`\) dışarıdan verilmez, sınıf içi parametrelerdir
Expand Down
244 changes: 244 additions & 0 deletions temel-kavramlar/arkaplanda-calisma/foreground-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
---
description: Android'de ön planda çalışan servisler
---

# 🌞 Foreground Service

## 🔰 Temel Hususlar

Kullanıcının bildirim veya arayüz ile haberi olan arkaplan görevleridir

* Önceli servislerdir ve öncelik seviyesi bildirilmelidir
* Kullanıcıya [kaldırılamayan bir bildirim](https://developer.android.com/guide/topics/ui/notifiers/notifications.html#foreground-service) gösterilmesi zorunludur
* Kullanıcının arkaplan işlemlerinden haberdar olması amaçlanır
* Servisin çalıştırılması için [`FOREGROUND_SERVICE`](https://developer.android.com/reference/android/Manifest.permission.html#FOREGROUND_SERVICE) iznine ihtiyaç duyulur
* Android'in [izin isteme hiyerarşisine](https://developer.android.com/guide/topics/permissions/overview) uygun ilerler
* İzin alınmadığı taktirde [`SecurityException`](https://developer.android.com/reference/java/lang/SecurityException.html) hatası verir

{% hint style="info" %}
🧙‍♂️ Android dokümanında [Running a service in the foreground](https://developer.android.com/guide/components/services#Foreground) alanında işlenmektedir
{% endhint %}

## 👮‍♂️ Gerekli İzinleri Alma

* Android 8.0 ve sonrası için [`FOREGROUND_SERVICE`](https://developer.android.com/reference/android/Manifest.permission.html#FOREGROUND_SERVICE) iznine ihtiyaç duyulur
* Örnek izin sistemi için alttaki kodu kullanabilirsiniz

```java
static final int PERMISSION_FOREGORUND = 1;

void startTelemetryService() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.FOREGROUND_SERVICE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.FOREGROUND_SERVICE)) {
Toast.makeText(this, "Haberleşme hizmeti için izne ihtiyaç vardır", Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.FOREGROUND_SERVICE}, PERMISSION_FOREGORUND);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.FOREGROUND_SERVICE}, PERMISSION_FOREGORUND);
}
}
} else {
startService(new Intent(this, TelemetryService.class));
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_FOREGORUND) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startTelemetryService();
}
}
}
```

{% page-ref page="../izinlerin-yoenetimi.md" %}

## 🧱 Temel Yapıyı Oluşturma

```java
public class TelemetryService extends Service {
private static final String TAG = "TelemetryService";

private Looper telemetryLooper;
private TelemetryHandler telemetryHandler;

public TelemetryService() {
}

private final class TelemetryHandler extends Handler {
public TelemetryHandler(Looper looper) {
super(looper);
}

@Override
public void handleMessage(@NonNull Message msg) {
try {
Log.i(TAG, "Mesaj alındı");
Thread.sleep(1000);
} catch (InterruptedException e) {
// Kesme isteği geldiğinde isteği uygulama
Thread.currentThread().interrupt();
}
stopSelf(msg.arg1);
}
}

@Override
public void onCreate() {
Log.i(TAG, "Servis oluşturuldu");

// Arkaplanda çalışacak thread'in tanımlanması ve başlatılması (UI thread'i bloklamaması lazım)
HandlerThread thread = new HandlerThread("TelemetryStartArguments", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();

telemetryLooper = thread.getLooper();
telemetryHandler = new TelemetryHandler(telemetryLooper);
}



@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "Servis başlatıldı");

Message msg = telemetryHandler.obtainMessage();
msg.arg1 = startId; // İsteklerin yönetimi için kimlikleri saklamalıyız
telemetryHandler.sendMessage(msg);

// Eğer servis öldüyse, bu dönüşten sonra Intent'siz tekrar başlat
return START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
return null;
// TODO: Return the communication channel to the service.
// throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public void onDestroy() {
Log.i(TAG, "Servis kapatıldı");
}
}
```

{% hint style="info" %}
🧙‍♂️ Ayrıntılı bilgi için [Create a Service](https://developer.android.com/guide/components/services#CreatingAService) alanına bakabilirsin.
{% endhint %}

## 🔔 Bildirim Ekleme

* Android'in yeni gelen sürümleriyle beraber [NotificationChannel](https://developer.android.com/reference/android/app/NotificationChannel.html) yapısı gelmiştir
* Bu yapı ile her bildirim kategorilere ayrılmıştır
* Uygulama üzerindeki tüm bildirimleri susturmak yerine, belli başlı kategorileri susturma avantajı sağlar
* Kategorilere göre bildirim şekillerini düzenlemeye yardımcı olur

![](../../.gitbook/assets/image%20%2817%29.png)

```java
public class TelemetryService extends Service {
private static final String TAG = "TelemetryService";

private static final int REQUEST_SHOW_CONTENT = 0;
private static final int REQUEST_STOP = 1;

static final String ACTION_START_SERVICE = "Start telemetry service";
static final String ACTION_STOP_SERVICE = "Stop telemetry service";

@Override
public void onCreate() {
Log.d(TAG, "Servis oluşturuldu");
startForeground();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String intentAction = intent.getAction();
if (intentAction != null) {
switch (intentAction) {
case TelemetryService.ACTION_START_SERVICE: {
Log.d(TAG, "Servis başlatıldı");
break;
}
case TelemetryService.ACTION_STOP_SERVICE: {
stopForegroundService();
}
}
}

// Eğer servis öldüyse, bu dönüşten sonra Intent'siz tekrar başlat
return START_STICKY;
}

public void startForeground() {
String channelId = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
channelId = createNotificationChannel();
}

// Bildirime tıklandığında main uygulamayı açma isteği oluşturma
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this, REQUEST_SHOW_CONTENT, intent, PendingIntent.FLAG_UPDATE_CURRENT);

// Bildirim üzerinden servisi kapatma isteği oluşturma
Intent stopSelf = new Intent(this, TelemetryService.class);
stopSelf.setAction(TelemetryService.ACTION_STOP_SERVICE);
PendingIntent pStopSelf;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
pStopSelf = PendingIntent.getForegroundService(this, REQUEST_STOP, stopSelf, PendingIntent.FLAG_CANCEL_CURRENT);
} else {
pStopSelf = PendingIntent.getService(this, REQUEST_STOP, stopSelf, PendingIntent.FLAG_CANCEL_CURRENT);
}

Notification notification = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.face_deteciton)
.setContentTitle("İçerik başlığı")
.setContentText("Buraya içerikleriniz ile ilgili detyaları yazın")
.setPriority(NotificationCompat.PRIORITY_MIN)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.addAction(R.mipmap.ic_launcher, "Kapat", pStopSelf) // Kapatma butonu ekleme
.build();

startForeground(101, notification);
}

@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel() {
String channelId = "channel id";
NotificationChannel channel = new NotificationChannel(channelId, "Bildirim kategorisi ismi", NotificationManager.IMPORTANCE_DEFAULT);
channel.setLightColor(Color.BLUE);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}

return channelId;
}

private void stopForegroundService() {
Log.d(TelemetryService.TAG, "Servis sonlandırılıyor");

stopForeground(true);
stopSelf();
}

@Override
public void onDestroy() {
Log.d(TAG, "Servis kapatıldı");
}

}
```

{% hint style="info" %}
🧙‍♂️ Detaylı bilgiler için [Create Notification](https://developer.android.com/training/notify-user/build-notification?hl=en), [PendingIntent](https://developer.android.com/reference/android/app/PendingIntent) alanlarına bakmanda fayda var
{% endhint %}

10 changes: 5 additions & 5 deletions temel-kavramlar/component-isimleri.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ In the figure above:

## 🍢 Seek Bar

![](../.gitbook/assets/image%20%288%29.png)
![](../.gitbook/assets/image%20%2810%29.png)

## ⚫ Progress Bar

![](../.gitbook/assets/image%20%2815%29.png)
![](../.gitbook/assets/image%20%2819%29.png)

## 🔀 Navigation Bar

![](../.gitbook/assets/image%20%2822%29.png)
![](../.gitbook/assets/image%20%2826%29.png)

## 🕎 Navigation View

![](../.gitbook/assets/image%20%286%29.png)
![](../.gitbook/assets/image%20%287%29.png)

## 💬 Alert Dialog

![](../.gitbook/assets/image%20%2823%29.png)
![](../.gitbook/assets/image%20%2827%29.png)

Loading

0 comments on commit a0d8e29

Please sign in to comment.