Proper integration of Admob Banner ads in JetPack Compose - android-studio

I am looking for correct integration of Admob Banner ads in my JetPack Compose View.
In my case, I used to load Banner Ads in LazyColumn between various LazyColumn Items. But I am having a problem with combination of LazyColumn and Banner Ad. The banner Ad loads perfectly initially, but once I scroll away from my Ad view and the banner Ad becomes hidden, and then when I scroll back to my banner ad view, the ad view starts to reload again and the previously loaded ad gets killed.
Can anyone please guide me how do I prevent the Banner Ad View to get killed when I scroll away without causing it to reload again and again
The code that I am using is -
//MainView where I load ad
#Composable
fun MainView(){
LazyColumn{
//other contents
item {
BannerAdView()
}
//other contents
}
}
//BannerAdView
#Composable
fun BannerAdView() {
AndroidView(
modifier = Modifier.fillMaxWidth(),
factory = { context ->
AdView(context).apply {
setAdSize(AdSize.BANNER)
adUnitId = context.getString(R.string.adId)
loadAd(AdRequest.Builder().build())
adListener = object : AdListener() {
override fun onAdLoaded() {
isAdLoaded = true
}
}
}
}
)
}

Related

How to show an image in the mobile application

I have a request to add the image from a stock item to the picking screen in the mobile app in Acumatica. I took a look at the Mobile Framework documentation but, there doesn't appear to be a way to show an image in the mobile app. Has anybody tried something like this?
TIA!
I don't think there is a control for ImageURL in the mobile app as of now.
However, as long as your screen holds a Header record with Files(attachments) you could still see the attachments(images) in the mobile application.
For this you can take as an example and guidance the EP301020 - Expense Receipt screen:
add screen EP301020 {
openAs = Form
add container "ClaimDetails" {
formActionsToExpand = 1
add layout "ReceiptNumberHeader" {
displayName = "ReceiptNumberHeader"
layout = "HeaderFirstAttachment"
add field "ReceiptNumber" {
forceIsDisabled = True
}
add field "Status" {
forceIsDisabled = True
}
}
add field "DetailsExpenseDetails#Description"
.....................
attachments {
imageAdjustmentPreset = Receipt
}
}
...............
}
See more details about the layout "HeaderFirstAttachment" here:
https://help.acumatica.com/(W(1))/Help?ScreenId=ShowWiki&pageid=bd31e3a8-538f-47d5-84ff-251ca3d03c43

How do I add the SendQuote Action to the Mobile App

I am trying to add the Send Quote action from the actions menu in the web app to the mobile app. This is on the sales quote screen (CR304500). I followed the documentation from the Mobile Framework guide, and I was able to add other buttons. The code I'm using for the mobile screen is
update screen CR304500 {
update container "QuoteSummary" {
add recordAction "SendQuote" {
behavior = Void
}
}
}
Thank you in advance.
Turns out because it was in the Actions Folder, I had to enter it as follows.
update screen CR304500 {
update container "QuoteSummary" {
add recordAction "SendQuoteActionsFolder" {
behavior = Void
}
}
}

Dynamically added menu (PXAction + MenuAutoOpen + AddMenuAction) gets hidden in some screens, but not others

I am trying to dynamically add a menu and related actions through a graph extension. The code I have written works in some screens but not in others. I can see the menu appear during post-back but it gets hidden right away: http://recordit.co/T5KSEz7QJv
I have spent a few hours investigating the problem and here's what I found so far:
If I don't add my action to a menu, it works in every cases. The issue is only when using AddMenuAction. I see that there's some logic inside PXAction to show/hide the menu based on visibility of the items inside the menu, but I couldn't figure the problem out.
If the menu itself is directly declared in the graph extension (using public PXAction... and attributes), it works as expected. It is not an option in my case because I am trying to create a generic mechanism that will allow me to add actions to any graph type.
The two following graph extensions highlight this problem - the first one is for Sales Orders entry, and the other for Business Account maintenance. They are identical, except for the graph type parameter:
//This extension works fine, button displays as expected
public class TestButtonsSO : PXGraphExtension<SOOrderEntry>
{
public override void Initialize()
{
base.Initialize();
Type primaryViewItemType = Base.Views[Base.PrimaryView].Cache.GetItemType();
var myMenu = PXNamedAction.AddAction(Base, primaryViewItemType, "MyMenu", "My Menu",
a => a.Get(),
new PXEventSubscriberAttribute[] { new PXButtonAttribute() { MenuAutoOpen = true } });
var action = PXNamedAction.AddAction(Base, primaryViewItemType, "MyMenu$Test", "Test",
a => throw new PXException("Clicked!"),
new PXEventSubscriberAttribute[] { new PXButtonAttribute() { } });
myMenu.AddMenuAction(action);
}
}
//The menu will appear during post-back but gets hidden right away
public class TestButtonsBAccount: PXGraphExtension<BusinessAccountMaint>
{
public override void Initialize()
{
base.Initialize();
Type primaryViewItemType = Base.Views[Base.PrimaryView].Cache.GetItemType();
var myMenu = PXNamedAction.AddAction(Base, primaryViewItemType, "MyMenu", "My Menu",
a => a.Get(),
new PXEventSubscriberAttribute[] { new PXButtonAttribute() { MenuAutoOpen = true } });
var action = PXNamedAction.AddAction(Base, primaryViewItemType, "MyMenu$Test", "Test",
a => throw new PXException("Clicked!"),
new PXEventSubscriberAttribute[] { new PXButtonAttribute() { } });
myMenu.AddMenuAction(action);
}
}
Upon the investigation, this issue seems to be caused by PXGridWithPreview corrupting ToolBarItemCollection in the DataSource. Your approach above will perfectly work on all Acumatica screens, which do not contain a PXGridWithPreview control. For screens already utilizing PXGridWithPreview, we'll have to wait until a fix is realised by Acumatica Engineering Team (will keep this item on my radar and post an update once the fix is available)

How To Add Monotouch Dialog to FlyoutNaviagtionController

I'm a noob to monotouch and can't manage to add table views to flyoutnavigation controller. Does anyone have an example?
** update
My setup is a bit complicated and after much hacking managed to get the static table cells displayed on my storyboard with the below config.
tab bar controller
|
-tab 1
|
-tab 2 - nav controller
|
uiview controller A - flyout nav A --> uiview controller A1...A3
|
uiview controller B - flyout nav B --> tableview controller B1 (static cells)
I've cast the tableview controllers as uiview controllers on the flyout navs' setup thus allowing the tableviewcontroller to be displayed correctly and navigated to main uiview controllers via sergues. For example in the flyouts setup:
NavigationRoot = new RootElement ("FlyoutNavigationB") {
new Section ("Pages") {
new StringElement ("A Table View with static cells")
}
},
ViewControllers = new [] {
TableViewControllerB1 as UIViewController,
},
This hack seems to work but cleaner solutions are warmly invited (as I'm only 2weeks dev experience with monotouch) and feel a little saddened that I have uiview controllers sitting unattached on the storyboard without ability to do sergues via the flyout nav. It almost behaves like old school xib development.
Anyway I'm experimenting with tying this upto monotouch dialog now but not yet sure how. Comments most welcome to aid my learning :P
* update
Ok I think I got it working by creating a subclassed dialogviewcontroller. Then passing this subclass instance into the ViewControllers array in flyoutnavigationcontroller like so:
public partial class MyDvcController : DialogViewController
{
public MyDvcController (UINavigationController nav): base (UITableViewStyle.Grouped, null)
{
navigation = nav;
Root = new RootElement ("Demos"){
new Section ("Element API"){
new StringElement ("iPhone Settings Sample", DemoElementApi),
}
};
}
}
In my calling flyoutnav controller:
// Supply view controllers corresponding to menu items:
ViewControllers = new [] {
new UIViewController { View = new UILabel { Text = "Address txt" }, Title = "Address" },
new MyDvcController(NavigationController) as UIViewController
}
My wish list is almost complete...now how to add custom upickerviews with lovely transparent input accessory views wired to inputviews so they show automatically from calling monotouch dialog elements...hmmmm...another quest awaits...
Are you trying to push a second list over inside the flyout? I couldn't get it to work either.
I got it to work by modifying the source and redoing how the selection list is setup--but those changes are on my machine at work. I'll try to push those when I have a chance.

how to place admob ad at the bottom in android,without using layout xml

I want to place an admob ad at the bottom of my apk, but the ad never show, and there is no layout xml in my apk,the layout is build up by an gameview class,
LogCat says:onFailedToReceiveAd(Ad request successful,but no ad returned due to lack of ad inventory)
here is my code
gameView = new GameView(this, display.getWidth(), display.getHeight());
setContentView(gameView);
RelativeLayout viewLayout = new RelativeLayout(GameActivity.this);
RelativeLayout.LayoutParams flLP2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
// Create the adView
AdView adView = new AdView(this, AdSize.BANNER, "xxxxxx");
// Add the adView to it
viewLayout.addView(adView,flLP2);
// Initiate a generic request to load it with an ad
AdRequest adTest = new AdRequest();
adTest.addTestDevice("xxxxxxxxxx");
adView.loadAd(adTest);
Are you using the correct test device id? Check the logcat log (tag "Ads"), there should be a line saying:
Ads: To get test ads on this device, call adRequest.addTestDevice("xyz");

Resources