help - Quick Help for Common Tasks
Fast reference for solving common Android development problems. Use this when you need quick code examples for ViewModel, Room, Hilt, API calls, testing, or deployment tasks.
/plugin marketplace add pluginagentmarketplace/custom-plugin-android/plugin install android-development-assistant@pluginagentmarketplace-androidFast reference for solving common Android development problems.
If you're a beginner:
/dev-guide/code-examples for referenceIf you have experience:
/code-examples for patterns1. Plan architecture (MVVM, Repository pattern)
2. Set up project with:
- Jetpack (ViewModel, Room, Navigation)
- Hilt for dependency injection
- Retrofit for APIs
3. Implement features incrementally
4. Write tests (Unit + UI)
5. Optimize performance
6. Deploy to Play Store
@HiltViewModel
class MyViewModel @Inject constructor(
private val repository: MyRepository
) : ViewModel() {
private val _state = MutableLiveData<State>()
val state: LiveData<State> = _state
fun doSomething() {
viewModelScope.launch {
_state.value = repository.getData()
}
}
}
// In Fragment
viewModel.state.observe(viewLifecycleOwner) { state ->
updateUI(state)
}
@Entity
data class Item(@PrimaryKey val id: Int, val name: String)
@Dao
interface ItemDao {
@Query("SELECT * FROM Item")
suspend fun getAll(): List<Item>
@Insert
suspend fun insert(item: Item)
}
@Database(entities = [Item::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun itemDao(): ItemDao
}
@HiltAndroidApp
class MyApp : Application()
@HiltViewModel
class MyViewModel @Inject constructor(
private val repository: MyRepository
) : ViewModel()
class MyFragment : Fragment() {
private val viewModel: MyViewModel by viewModels()
}
interface ApiService {
@GET("/items")
suspend fun getItems(): List<Item>
}
val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()
val api = retrofit.create(ApiService::class.java)
val items = api.getItems() // In coroutine
// Navigate
findNavController().navigate(R.id.action_go_to_detail)
// With arguments
findNavController().navigate(
MyFragmentDirections.actionGoToDetail(itemId = 123)
)
// Pop back stack
findNavController().popBackStack()
@RunWith(RobolectricTestRunner::class)
class MyViewModelTest {
private val repository = mockk<MyRepository>()
private lateinit var viewModel: MyViewModel
@Before
fun setup() {
viewModel = MyViewModel(repository)
}
@Test
fun `test something`() {
coEvery { repository.getData() } returns testData
viewModel.doSomething()
assertEquals(testData, viewModel.state.value)
}
}
@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class MyActivityTest {
@get:Rule
val activityRule = ActivityScenarioRule(MyActivity::class.java)
@Test
fun testButton() {
onView(withId(R.id.button))
.perform(click())
onView(withId(R.id.result))
.check(matches(withText("Expected text")))
}
}
val encryptedPrefs = EncryptedSharedPreferences.create(
context, "secret",
MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build(),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
encryptedPrefs.edit { putString("token", "secret_value") }
1. Increment versionCode and versionName
2. Enable minification:
minifyEnabled = true
3. Build release bundle:
./gradlew bundleRelease
4. Sign with keystore
5. Upload to Google Play Console
6. Configure app listing
7. Start staged rollout (5% → 25% → 100%)
// ❌ LEAK
object Singleton {
lateinit var context: Context
}
// ✅ FIX
object Singleton {
var context: WeakReference<Context>? = null
}
// ✅ Also unregister listeners
override fun onDestroy() {
super.onDestroy()
unregisterReceiver()
}
Memory:
Battery:
Rendering:
"Can't create instance of ViewModel"
"NullPointerException on view"
"Fragment not attached to context"
"ANR (Application Not Responding)"
# Build debug APK
./gradlew assembleDebug
# Build release bundle
./gradlew bundleRelease
# Run tests
./gradlew test
# Run instrumentation tests
./gradlew connectedAndroidTest
# Check lint
./gradlew lint
# Profile app
./gradlew profileRelease
Official Docs:
Training:
Tools:
Before launching to Play Store:
Need more detailed help?
/dev-guide - Complete development guide/code-examples - Real-world code examples