I have an App which was using the old ADMOB SDK. I have started using the Google play services library for showing the ADMOB interestial ad. I have an Ad every time the Activity starts.
ISSUE:
In some Phones I could see the Activity restarts after every close of the AD. Because of this I could see only the Ads. Also I found that the activity reaches onDestroy(). Is there is any way to avod it ?
Kindly help me to resolve this
Android Manifest
<supports-screens
android:xlargeScreens="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true" />
<!-- Used to request banner and interstitial ads. -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Used to avoid sending an ad request if there is no connectivity. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/memorygamefreelogo"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<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 required to show ad overlays. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<activity
android:name="com.example.Splash"
android:label="Memory Game"
android:noHistory="true"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.splash.MemoryHome"
android:label="memorygame"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
<intent-filter>
<action android:name="android.intent.action.memorygame.free.MEMORYHOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.splash.MemoryGame"
android:label="memorygame"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
<intent-filter>
<action android:name="android.intent.action.memorygame.free.MEMORYGAME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
When you show an interstitial ad a new (InterstitialAd) Activity is started. This means that your current Activity will no longer be visible and Activity#onStop will be called.
The Android framework may also decide to remove your Activity from memory altogether. If it does so, it may call Activity#onDestroy. This explains the differences you see between some of your phones. I'm not aware of any way to influence this behaviour.
You could modify your onCreate method:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
showAd();
}
}
Like this, the Ad shows only on fresh start.
Related
I have an app on the Google Play Store. I've found an interesting bug here - when I'm sending my app to background (by pressing home) and then clicking on the app icon again, it opens the main screen.
I read some article (https://medium.com/#elye.project/three-important-yet-unbeknown-android-app-launcher-behaviors-part-2-139a4d88157) about it, tried all application states, but the behavior remains the same. However, If I will open my ADB app (or from Studio) all works just fine.
How to solve this? My manifest file looks like following:
<uses-feature
android:name="android.hardware.touchscreen.multitouch"
android:required="false" />
<uses-feature
android:name="android.hardware..accelerometer"
android:required="true" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<application
android:name=".MyApplication"
android:launchMode="singleTop">
<activity
android:name=".ui.main.MainActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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:host="signin"
android:scheme="appprefix" />
</intent-filter>
</activity>
<activity
android:name=".ui.view.Acitivity2"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:launchMode="singleTop"/>
<activity
android:name=".ui.view.Acitivity3"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:launchMode="singleTop"/>
A possible workaround for market launches. The market launches the main activity on top of other activities. We never want this to happen. Instead, we should check if we are the root and if not, we finish the current. Add following code on your launcher activity onCreate()
if (!isTaskRoot()) {
final Intent intent = getIntent();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) &&
Intent.ACTION_MAIN.equals(intent.getAction())) {
finish();
return;
}
}
This question already has an answer here:
duplicate registration for activity "androidstutio"
(1 answer)
Closed 4 years ago.
We decided to make an intro/welcome screen to our app. The activity called Welcome Activity needs to be launched when user goes to the application for the first time. All other times Main Activity needs to be launched. That's how I've done it in Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.google.android.gms.samples.vision.ocrreader"
android:installLocation="auto">
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:name=".OcrApplication"
android:allowBackup="true"
android:fullBackupContent="false"
android:hardwareAccelerated="true"
android:icon="#drawable/icon"
android:label="Ingredient analysis"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="ocr" />
<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:windowSoftInputMode="stateHidden|adjustPan"
android:exported="true"
>
</activity>
<activity
android:name=".OcrCaptureActivity"
android:label="Read Text" />
<activity android:name=".ListResult" />
<activity android:name=".AllIngredients" />
<activity android:name=".IngredientDescription" />
<activity android:name=".Instruction" />
<activity android:name=".WelcomeActivity"> </activity>
</application>
However, there is an error - Duplicate registration for activity in this line:
Duplicate registration for activity happens when you register same Activity twice.
In your case you have registered WelcomeActivity twice. Once immediately after <application> tag and once at the very end.
Remove following re-registration line from end of your mainfest (before </application> tag)
<activity android:name=".WelcomeActivity"> </activity>
this problem usually occurs while there will be same name <activity tags multiple time.
In you code, found that, you used WelcomeActivity twice.
remove the <activity android:name=".WelcomeActivity"> </activity> (see at the last portion of your code, you will find that. just remove the line).
Ran into this issue trying to get Interstitial Ads to work on my first android app. Being a complete novice I really had on idea how to add the "useClientJar" flag to the Intent Extras.
This wasn't the issue, it's actually an error in the AndroidManifest.xml and I'm posting this question/answer because it's one of the few situations I've run into with only 5 relevant google results, the top one being a piece of IRC chat with one poor guy running into the same problem as me.
The issue is that I had foolishly made my main activity into the AdActivity in the AndroidManifest.xml like this:
<activity
android:name="com.google.android.gms.ads.AdActivity" <!-- notice this name, this means the interstitial ad is now the main activity! -->
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The fix of course was to correct this like so:
<!-- They are now two separate activities -->
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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" />
My application is never shown in the RECENT APPS list whenever I put the following piece of code in my activity's manifest entry
<category android:name="android.intent.category.DEFAULT" />
If I remove above line it works fine. I've also made sure that the following flags are set to false-
android:noHistory="false"
android:excludeFromRecents="false"
But still its never displayed even if I launch app manually.
In case anybody wants to have a look the manifest, its-
<?xml version="1.0" encoding="UTF-8"?>
<uses-sdk android:minSdkVersion="8" />
<application
android:name="com.raj.poc.copypaste.MainApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".CopyPasteActivity"
android:launchMode="singleTop"
android:noHistory="false"
android:excludeFromRecents="false"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEARCH_LONG_PRESS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
It may also happen if you set
<activity... android:label=""/>
for your main Activity
This is the only activity in your application, right?
You are using the category tag twice. You have written in your code
<category android:name="android.intent.category.LAUNCHER" />
so you have already selected the category. When you add a new activity then you will write the Default category tag.
I have a main activity. From it, I am calling 2 other sub activities called FacebookLogin and Twitterlogin. I am using the following code in AndroidManufest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examples.Kikin" android:versionCode="1"
android:versionName="1.0">
<!-- THIS IS THE BEGINNING OF SHARING LINKS FROM THE BROWSER -->
<application android:icon="#drawable/kikinlogo"
android:label="#string/app_name" android:debuggable="true">
<activity android:name=".Kikin" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".FacebookLogin" android:label="#string/app_name">
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<!-- <data android:mimeType="image/png" /> -->
</intent-filter>
</activity>
<activity android:name=".TwitterLogin" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="yourapp" android:host="twitt"></data>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
Am i doing it right?
Should i nest the FacebookLogin and TwitterLogin activities in the main activity?
The aforesaid 2 classes are in the package com.examples..
* is the same wherever used.
The labels for your FacebookLogin and TwitterLogin appear to be missing an '#' - change them to android:label="#string/app_name"
There's no such thing as a "subactvity". Just because you call one activity from another doesn't mean it's a "subactivity".
You can't nest activity tags in the manifest and you'd probably get a compile error if you tried.
in manifest you can set only one activity in launcher tag okay android does support multiple launcher activity.
The manifest you posted looked fine.
But regarding your comment about the error message "Have you declared this activity in AndroidManifest.xml?", you need to check carefully the package and class name of the Activity you are trying to launch, and make sure that it matches the <activity android:name> you have written in the manifest.
All the info you need should be in the error message.
Don't nest activity declarations, just have them all as elements in your application element:
<manifest ...
<application ...
<activity ...
</activity>
<activity ...
</activity>
<activity ...
</activity>
</application>
</manifest>
The sample you posted here (indenting aside) looks fine.
Maybe you have tested it already but just try declaring your activities with the full path (although you have already declared it in the package tag). So, instead of using
<activity android:name=".TwitterLogin" />
use
<activity android:name="com.examples.Kikin.TwitterLogin" />
Sometimes problems are caused because of that.
I know this is an old thread but Im having the same problem and in my case specifying full package name doesnt help. Have you already found a solution? I`m really interested in knowing how to avoid this error.