error: cannot find symbol class AdvertiseActivity - java

I'm new to Android app development so please be patient with me. I'm writing an app that gets the GPS location from Google Play services and then broadcasts the data over Bluetooth. I have a LocationActivity that gets the location, and an AdvertiseActivity that broadcasts the data.
My problem is that I'm having a hard time understanding the file structure in android apps, so I suspect my lack of understanding is why I'm getting the error.
Here is a snippet of LocationActivity where the error is:
#Override
public void onLocationReceived(Location location) {
Intent i = new Intent(LocationActivity.this, AdvertiseActivity.class) //problem is here
.putExtra("latitude", location.getLatitude());
startActivity(i);
}
Why can't the compiler find AdvertiseActivity.class? Is something wrong with my manifest below?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name="com.android.app.LocationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.android.app.AdvertiseActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Please help. Thanks!

You are using two activities as MAIN .From manifest, Remove:
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DEFAULT" />
From AdvertiseActivity's activity tag. Hope this helps.

Remove these lines from manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
And keep only this line.
<activity android:name="com.android.app.AdvertiseActivity"/>

An Application can have only one android.intent.action.MAIN in Startup Activity. In your LocationActivity you already defined so remove intent-filter from AdvertiseActivity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
so its like
<activity android:name="com.android.app.AdvertiseActivity"/>

Related

I want apk to open the second page first

I made the second page a menu. I want the second page to open when the apk opens. How can I do this with code? I only need a code
Inside your AndroidManifest.xml file you will have something like this:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And you something like this for other acitivities:
<activity
android:name=".SecondActivity" />
What you need to do is just copy/paste that <intent-filter></intent-filter> tags to the SecondActivity, and you get this:
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and
<activity
android:name=".MainActivity" />
Your code in AndroidManifest.xml file is like following:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"/>
You just have to set the second activity as the launcher of the app, i.e copy/paste <intent-filter> from .MainActivity to .SecondActivity. Like this:
<activity android:name=".MainActivity"/>
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And that's it! Now the second page opens the app.

Why is my app icon showing as blank from the app grid list with android studio?

I have tried a many different links on here to figure out why my app will not show on the list of app when I download it, but I have had no luck. I have tried many different things. Is there something I am missing with getting Intent Filters set up in android studio?
<application
android:name=".GdpApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppThemeNoActionBarOrangeMain">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<activity
android:name=".SplashActivity"
android:screenOrientation="landscape"
android:theme="#style/AppThemeNoActionBarSplash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
'''
Not 100% sure but it does seem strange that you have 2
"android.intent.action.MAIN"

Error:Execution failed for task ':app:processDebugManifest'. Manifest merger failed with multiple errors, see logs

My code was compiling before but stopped working and is giving this error
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
log
java.lang.RuntimeException: Activity name cannot be empty. at
com.android.tools.idea.model.MergedManifest$ActivityAttributes.(MergedManifest.java:579)
at
com.android.tools.idea.model.MergedManifest.syncWithReadPermission(MergedManifest.java:418)
at
com.android.tools.idea.model.MergedManifest.access$000(MergedManifest.java:55)
at
com.android.tools.idea.model.MergedManifest$1.run(MergedManifest.java:331)
at
com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:945)
at
com.android.tools.idea.model.MergedManifest.sync(MergedManifest.java:328)
at
com.android.tools.idea.model.MergedManifest.getActivities(MergedManifest.java:464)
at
com.android.tools.idea.run.activity.DefaultActivityLocator.lambda$computeDefaultActivity$97(DefaultActivityLocator.java:78)
at
com.intellij.openapi.project.DumbService$1.run(DumbService.java:89)
my manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:header=".MyApplication"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:header=".ui.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:header="android.intent.action.MAIN" />
<category android:header="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:header=".ui.ResponseActivity"
android:label="#string/title_item_detail"
android:parentActivityName=".ui.MainActivity"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:header="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
</activity>
</application>
what could be the cause of this?
Use this for your main activity because name field is required to identify an activity not the header so replace every header with name field
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
instead of this
<intent-filter>
<action android:header="android.intent.action.MAIN" />
<category android:header="android.intent.category.LAUNCHER" />
</intent-filter>
So it will
<activity
android:name=".ui.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and do the same for other activities too
You have to write android:name=".ui.activityName" in your activity tag of manifest file for each of the activity.
Hope this helps!

android app doesnt crash after installiation

So I have very weird problem with android app that I developed that I really do not understand how to address.
Description of the problem: When I run the app in my emulator(and many other emulators) the app works perfectly, but when I list it on Google Play and some user download the app, it automatically crashes. so I just wonder if my androidmainfest is properly written.
*the program written in esclipse, java, android.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app"
android:versionCode="6"
android:versionName="1.5" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.SurfaceExampleView"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.example.start" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.RulesGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.rules" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.PolicyGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.policy" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.RevenueGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.revenue" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.ShopGame"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.shop" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
You have posted only your manifest and not the logs. My guesses based on that is the problem may be within your package declaration, rest everything seems fine.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app".....
The package should be unique and its like what we call package in java world. You have declared it as com.app whereas your app is using com.example.... package. Also com.app maybe used by other app.The package name defines your application's identity.
Once you publish your application, you cannot change the package name. As the package name defines your application's identity, so if you change it, then it is considered to be a different application and users of the previous version cannot update to the new version. So you may have to upload another app with different package name.
Try getting logs(use crashlytics) for your crash and we can look into it for the root cause.

android change start activity

I am new to android so I want to change the starting of the application in android manifest but each time the application is stopped cs worked is that we must change the java codes aussie
here is the xml code:
<application
android:icon="#drawable/icon"
android:label="hello">
<activity
android:name=".activity.ServersActivity"
android:label="#string/app_name"
android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.AddServerActivity"
android:label="#string/add_server_label">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="irc"/>
</intent-filter>
</activity>
For setting the starting activity, you'll have to add the following Intent Filter to the activity in your AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Please note that you should only add this Intent Filter to one of your Activities. Otherwise, you might experience unexpected behaviours.
There is no way to change the starting activity by code.
Cut this line and paste it inside activity tag to whom you want as starting activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
For eg: Making AddServerActivity as stating activity
<activity
android:name=".activity.ServersActivity"
android:label="#string/app_name"
android:launchMode="standard">
</activity>
<activity
android:name=".activity.AddServerActivity"
android:label="#string/add_server_label">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="irc"/>
</intent-filter>
</activity>

Categories