Button does not show in emulator in Android Studio - java

I am fresh new to Android development. I just started but when I try to run a basic app with only one button, the button just simply does not show in emulator.
I looked everywhere, even saw similar question on stackOverflow from 2 years ago but answers do not suit my problem
Please tell me what part of code should I add here or anything else to get my app going. Thanks!
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

I can't tell without showing your code. But I think you did not add constraints to your button.
Constraint Layout

Related

How to fix the default activity not found problem?

my problem is related to Android Studio.Whenever I try to run my app I get an error that says default activity not found.Please help me out,it's really important.Thank you in advance!
Just in case,I've got 2 classes: the first one is MainActivity,the second one is CatRepository
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cats">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Try to replace <activity android:name=".ui.MainActivity"> by <activity android:name=".MainActivity">
Try putting full package name of your Activity.
You can try invalidating cache and restart.
File -> Invalidate Cache/Restart
Also after doing this, sync your project. : File-> Sync Project with Gradle Files

Android Login Screens switch

ANDROID STUDIO LOGIN SWICTH TO MAIN ACTIVITY
This is the error it shows me
Unexpected error while executing: am start -n "com.company.appname/com.company.appname.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while Launching activity
Am working on a social app and am trying to switch the screen to a login screen as soon as I enter the app but it keeps crashing on the emulator showing errors.`
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".LoginActivity"></activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
`
Goto logcat and select error in drop down menu and see why yohr app is crashing.
If you want more explanation then please upload your work and logcat error So we can see what actual problem occur.

Problem changing the main activity in Android studio project

I have created the MainActivity for my Android studio project, but after creating it I am adding a Login screen that I want to be the starting activity when the app launches. I changed the AndroidManifest.xml file to include the correct intent-filters for the login activity.
The app launches correctly with the login activity, but the problem is that now when I proceed to the MainActivity the buttons and fragments inside of it don't work anymore. The buttons don't respond to being clicked, and the fragments just don't appear at all.
Here is my code for the Android manifest file. All I changed was I switched .Login and .MainActivity
When I switch them back everything in MainActivity works correctly.
Is there something else I need to change for all the functionality of MainActivity to work correctly, even when it's not the starting activity when the app launches?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".LocationService" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name=".MainActivity"></activity>
</application>

How to change app subtitle in the head section

A screenshot of my activity preview
I'm new to android studio and have been following various tutorials online. Cant find the answer to this problem. if i change the app_name in the strings.xml, the name on the picture posted above also changes and if i generate the apk it also acts as the app name. I tried to add another string on the strings.xml but nothing changes. Is there a way to edit the title above without changing the final app name
strings.xml code
<resources>
<string name="app_name">Hello world</string>
That's because the same String is being used in both the layout where your image shows, and in your Manifest file.
You might recognize this code inside your AndroidManifest.xml file:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Note the part that says android:label="#string/app_name". That's the String that your app will show as the app name.
So if you want to use two different names, one for the app name and one for inside your layout, simply create two different Strings and assign one to the AndroidManifest.xml and the other to whichever layout you're image shows.
Use the app_name in the intent-filter of the launcher activity. and use a different string for android:label of your activity. Manifest would look like something this -
<activity
android:name=".MainActivity"
android:label="#string/title_main_activity"
android:icon="#drawable/icon">
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And create <string name="title_main_activity">Hello Main Activity</string>

Trying to start Google Play Services Games example

I'm very new to Android studio, so this is probably a stupid question.
As of current I'm trying to follow this tutorial:
https://developers.google.com/games/services/android/quickstart
and got stuck at step 1 almost right off the bat. I downloaded the whole project as I'm trying to start and test "Typeanumber". Upon importing I went to "TypeaNumber" and changed the AndroidManifest.XML to a random domain. Quite obviously this didn't change anything. I still can't run the project and there're errors everywhere.
The XML looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pieps.testgame">
<application
android:supportsRtl="true"
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity
android:name="com.google.example.games.tanc.MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
In the source, where I find the classes, there're like 5 directories that all seem exceptionally redundant. In the classes the wrong package is displayed as well.
Am I suppose to change all packages throghout the entire project(if so the documentation fails pretty hard)? What am I suppose to do to get this working?

Categories

Resources