How Do We Call loadAd Method of NativeBannerAd More Than Once? - android

I'm just trying to manage fail scenarios of ads in my app. So, after onError triggered due to some reason(e.g no network) I just called loadAd method of NativeBannerAd like below. But app crashed with called more than once error.
mFacebookNativeBannerAd = NativeBannerAd(context, id)
val builder = mFacebookNativeBannerAd.buildLoadAdConfig()
builder.withAdListener(object : NativeAdListener {
// ...
// Other callback methods
override fun onError(p0: Ad?, error: AdError?) {
mFacebookNativeBannerAd.loadAd() // --> 'called more than once' exception
}
})
mFacebookNativeBannerAd.loadAd()
I didn't see any description about this exception on documents. NativeAd, NativeAdsManager, InterstitialAd objects works with above scenario. But NativeBannerAd does not.
How can i load the ad again ?
The audience version i'm using is audience-network-sdk:5.6.1

Once the Facebook NativeBannerAd is failed then a new banner object needs to be created for every reload because the same object cannot be used again so you can create a method which will instantiate a new NativeBannerAd object and load it.
You must be thinking Why not reuse the same object from onError?
Because it's a code smell. In case of network error(your use case), the add will keeps on trying to load it self(can add retry logic but still code smell) and eventually will crash your app with StackOverflowException due to recursive behaviour.
Documentation reference as POC
Ad Instance is not an ad manager. You are supposed to
instantiate a new instance whenever you need "reload" an ad for native
ads and banner ads.

Related

How to trigger / debug backdoor functionality in Xamarin.Forms.UITesting?

I'm trying to add a BackdoorMethod to a Xamarin.Forms application to bypass the login (IDP - opened in chrome browser) step. I have the feeling that the method is not getting triggered, but not sure, and I don't know how could I make sure about it.
I've read the documentation here: https://learn.microsoft.com/en-us/appcenter/test-cloud/uitest/working-with-backdoors
Check this thread: https://forums.xamarin.com/discussion/85821/xamarin-uitest-backdoor-on-droid-with-splash-screen-how-do-i-access-my-mainactivity
Checked this example: https://github.com/brminnick/UITestSampleApp/tree/master/Src
In the MainActivity.cs file I've defined the BackdoorMethod:
[Preserve, Export(nameof(BypassLoginScreen))]
public string BypassLoginScreen()
{
// some additional code here. the code is working, when I called it
// directly from OnCreate it was executed without any error
return "called";
}
From the test case i'm trying to invoke it like:
public constructorMethod(Platform platform)
{
this.platform = platform;
app = AppInitializer.StartApp(platform);
var result = app.Invoke("BypassLoginScreen"); // result == "<VOID>"
}
I'm not getting any error message, the method simply not called, or not returns anything. (or i don't know what's happening there with it, because breakpoint also not working as the app started from the device)
This should be already working. I have similar code and it works for me.
you can add inside your function
Android.Util.Log.WriteLine(Android.Util.LogPriority.Info, "BypassLoginScreen", $"Some text as info");
And observe the result in Device Logs, Filter by BypassLoginScreen to see if there is any log created with the tag BypassLoginScreen

Facebook's NativeAdsManager gives always the same ad

I'm using Facebook's NativeAdManager for Android as intended:
nativeAdsManager = new NativeAdsManager(context, "my_placement_id", 3);
which should load me 3 different ads, and them allow me to get them in my adapter using:
NativeAd adItem = nativeAdsManager.nextNativeAd();
but for some reason I always get the same ad. According to their reference:
The NativeAdsManager provides a mechanism to fetch a set of NativeAds and then use them within your application. The recommended usage is to call nextNativeAd() at the moment when you are about to render an ad. The NativeAdsManager can hold at most 10 unique ads at once but supports giving out as many ads as needed by cloning over the set of NativeAds it got back from the server which can be useful for feed scenarios.
Am I missing something here?

Xamarin forms app long loading if resolve dependency

Long first loading of instance of any type registered in Resolver.
I tried to load random type in background using Thread and BackgroundWorker during base page opening and in MainActivit. The problem remained in any case. Only now during the application loading.
Appp.xaml.cs
if (!Resolver.IsSet)
{
var resolverContainer = new SimpleContainer();
resolverContainer.Register<ICartService, CartService>();
Resolver.SetResolver(resolverContainer.GetResolver());
}
And when i tried to get instanse of ICartService it's take 3+ seconds just for this operation.
It looks like:
Resolver.Resolve<ICartService>();

How to have a callback for when a crash occurred, while using Crashlytics SDK?

Background
We use Crashlytics SDK to manage app crashes and get needed information about them.
So far, the information that the SDK automatically gathered was enough
The problem
I'd like to add more information for each crash, such as: available&total heap memory, activity stack,...
Thing is, I don't see a way to achieve this.
I know that the way Android framework works with unhandled exceptions is pretty easy (using Thread.setDefaultUncaughtExceptionHandler) and it's probably how the SDK works, but I can't find where to use the listener of the SDK itself.
What I've tried
The SDK has a listener, but it seems it's not of the current session, as shown here. The function name is "crashlyticsDidDetectCrashDuringPreviousExecution" , meaning it's of the previous session. Same callback was available before in deprecated methods.
There are "Custom Logging" and "Custom Keys" features, but those occur when I call them (not right when the crash occurs).
The question
Is there a way to add extra information to Crashlytics right when a crash occurs ?
If so, how?
Try creating an UncaughtExceptionHandler and use Custom Key(s) to store the information you want to be associated with your crash report.
Create your custom UncaughtExceptionHandler (ensuring that it will pass exception to default UncaughtExceptionHandler to be handled later via Crashlytics).
In the uncaughtException method add custom logic to set your key e.g. Crashlytics.setString("available_memory", "5784");
Check your Crashlytics dashboard to view your custom key(s) when your app crashes
Create a custom Application subclass to hold your logic:
public class MyApplication extends Application {
private static Thread.UncaughtExceptionHandler mDefaultUncaughtExceptionHandler;
private static Thread.UncaughtExceptionHandler mCaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable ex) {
// Custom logic goes here
// Calculate available memory
Crashlytics.setString("available_memory", "5784");
// This will make Crashlytics do its job
mDefaultUncaughtExceptionHandler.uncaughtException(thread, ex);
}
};
#Override
public void onCreate() {
super.onCreate();
// Order is important!
// First, start Crashlytics
Crashlytics.start(this);
// Second, cache a reference to default uncaught exception handler
mDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
// Third, set custom UncaughtExceptionHandler
Thread.setDefaultUncaughtExceptionHandler(mCaughtExceptionHandler);
}
}
Remember to specify the name of your Application subclass in your AndroidManifest.xml’s tag
<application android:name="MyApplication">

Chartboost Interstitial won't show Ads on Unity

Lately, I have been trying to add static interstitial ads into my Unity game. For some reason, I could not get the system to show anything, or even react to me. After trying to work with the base Chartboost plugin, I tried to match a tutorial that I was following and purchased Prime31's Chartboost plugin and have been using that. However, neither the base plugin, nor Prime31's plugin, seem to be allowing me to show any ads. The code is pretty much done inside a single object, and it seems simple enough.
public class Advertisement : MonoBehaviour {
public string chartboostAppID = "5461129ec909a61e38b1505b";
public string chartboostAppSignature = "672b3b34e3e358e7a003789ddc36bd2bc49ea3b5";
// Use this for initialization
void Start () {
DontDestroyOnLoad(this.gameObject);
ChartboostAndroid.init (chartboostAppID, chartboostAppSignature, true);
ChartboostAndroid.cacheInterstitial(null);
}
void OnLevelWasLoaded(int level) {
ChartboostAndroid.cacheInterstitial(null);
if(Application.loadedLevelName == "Network Lobby") {
showAds();
}
}
public static void showAds() {
Debug.Log("Showing ad");
ChartboostAndroid.showInterstitial(null);
}
}
As you can see, it's pretty straightforward. This object is created at the game's splash screen, which appears only once, and it's never destroyed until the program ends. The goal is, whenever I enter the lobby scene, I want to see an ad before going to the lobby's menus. As it is, I do see the log printing "Showing ad", so I know the function is being called. However, nothing appears. Do I need to disable the GUI system first? Is there a step I'm missing?
I have already performed the following steps:
I have created and registered the app with chartboost, as well as double and triple checked the AppID and App Signature.
I have created a publishing campaign and registered it to the app.
I double-checked the orientation and confirmed that it's correct.
I registered this specific device as a test device.
The tutorial showed a call to ChartBoostAndroid.OnStart(), but there was no function like that for me to call. Perhaps that is from an older version?
I emailed Chartboost support and have not heard from them yet. I do not have that much time on this project, so if anyone can offer help, I'd appreciate it.

Categories

Resources