-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2be398d
commit 52bcad1
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
description: Android üzerinde Global Variable kavramı ve oluşturulması | ||
--- | ||
|
||
# 🌍 Global Değişkenler | ||
|
||
## 🔰 Neden kullanılır? | ||
|
||
* 🎳 Activity arası yüksek boyutlu veri taşımak maliyetlidir, bu yapı ile statik olarak saklanır | ||
* 💫 Her class tarafından değişkenler aktarılmadan, direkt buradan kullanılır | ||
* 👮♂️ Güvenli bir yapı olduğundan, sorunsuz çalışmayı sağlar | ||
* ✨ Hızlı ve kullanışlıdır | ||
|
||
## ⭐ Global Variable Örneği | ||
|
||
```java | ||
import androidx.annotation.NonNull; | ||
|
||
class Globals { | ||
|
||
private News selectedNews; | ||
|
||
private static Globals INSTANCE; | ||
|
||
private Globals() { | ||
} | ||
|
||
static synchronized Globals getInstance() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new Globals(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
void setSelectedNews(@NonNull News news) { | ||
selectedNews = news; | ||
} | ||
|
||
@NonNull | ||
News getSelectedNews() throws NullPointerException { | ||
if (selectedNews == null) { | ||
throw new NullPointerException("The selected news invoked without creation"); | ||
} | ||
return selectedNews; | ||
} | ||
} | ||
``` | ||
|
||
## 🔗 Faydalı Kaynaklar | ||
|
||
{% embed url="https://androidresearch.wordpress.com/2012/03/22/defining-global-variables-in-android/" %} | ||
|