Reputation: 11
in my first Android App I've created the NoteActivity (which is not MainActivity) and fragments, database, viewmodels, navigation etc. for this activity.
The problem is when i open the app using emulator after clicking the button which should open NoteActivity its navigates to MainActivity instead.
I think there's meybe some problem in AndroidManifest or build.gradle implementations.
AndroidManifest (DzennikPodrozy is mentioned NoteActivity) here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:allowBackup="true"
android:requestLegacyExternalStorage="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DuoTravel_v14"
tools:targetApi="31">
<activity
android:name=".DzennikPodrozy"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="andorid.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".MapyActivity"
android:exported="false"
android:label="@string/title_activity_mapy"
android:theme="@style/Theme.DuoTravel_v14" />
<activity
android:name=".StronaGlowna"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="*************************************" />
</application>
<queries>
<intent>
<action android:name="android.intent.action.MANAGE_EXTERNAL_STORAGE" />
</intent>
</queries>
</manifest>
Build.gradle (Module)
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.kapt")
id("kotlin-parcelize")
id("kotlin-kapt")
}
android {
namespace = "pl.duotravel.duotravel_v14"
compileSdk = 34
defaultConfig {
applicationId = "pl.duotravel.duotravel_v14"
minSdk = 28
targetSdk = 34
versionCode = 1
versionName = "1.0"
kapt {
correctErrorTypes = true
}
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures{
viewBinding = true
}
}
dependencies {
implementation ("pub.devrel:easypermissions:3.0.0")
implementation("androidx.fragment:fragment-ktx:1.6.2")
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.gms:play-services-maps:18.2.0")
implementation("androidx.navigation:navigation-fragment-ktx:2.7.5")
implementation("androidx.navigation:navigation-ui-ktx:2.7.5")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
// Architectural Components
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")
// Room
implementation("androidx.room:room-runtime:2.6.0")
implementation("androidx.room:room-ktx:2.6.0")
// Navigation Components
implementation("androidx.navigation:navigation-fragment-ktx:2.7.5")
implementation("androidx.navigation:navigation-ui-ktx:2.7.5")
implementation("androidx.navigation:navigation-dynamic-features-fragment:2.7.5")
}
Build.gradle (Project)
import com.android.build.gradle.internal.dsl.decorator.SupportedPropertyType.Collection.List.type
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.1.3" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath ("com.android.tools.build:gradle:7.5.1")
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin")
classpath ("androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0")
}
}
For a long team Ive been searching the problem in the NoteActivity codes but its seem to be complete.
Its not a problem if You need more codes from the project to help me
Thank You guys!
Upvotes: 0
Views: 35
Reputation: 57043
The mainfest (what the App contains) determines what the App consists of, including the activity that is first started.
The activity that has the action .MAIN
is the activity that is started. By default when you create a project it will be MainActivity.
i.e. you have
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To make the DzennikPodrozy the activity that is started then move the action from the MainActivity to the DzennikPodrozy activity.
A simplified minimal example. Steps taken:-
So the manifest includes:-
<activity
android:name=".DzennikPodrozy"
android:exported="true" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and when the App runs MainActivity is started:-
Changing the manifest to:-
<activity
android:name=".DzennikPodrozy"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>
Then :-
i.e. the TextView has the Teal background as per the layout for the DzennikPodrozy activity.
Upvotes: 1