Avijit Karmakar
Avijit Karmakar

Reputation: 9408

InMobiBanner is not initialized

I am getting this error while integrating InMobi Banner ad.

InMobiBanner is not initialized. Ignoring InMobiBanner.load()

I am using version 7.0.4 of InMobi Ads SDK. I have followed the instructions given in the documentation.

How can I fix this problem? Please help me regarding this.

Upvotes: 3

Views: 1730

Answers (3)

Avijit Karmakar
Avijit Karmakar

Reputation: 9408

Finally, I got the solution. Somehow, InMobiBanner is not working if the placement id is given in XML layout. So, we have to initialize the InMobiBanner programmatically with the Java code.

But complete your profile information and add your payment information before integrating the InMobi SDK. Also, don't create any placements before that.

Step 1:

Initialize the InMobiSdk in your Application file with the below code:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        InMobiSdk.init(this, "Your Account ID");
        InMobiSdk.setLogLevel(InMobiSdk.LogLevel.DEBUG);
    }

}

Step 2:

Add the Application file in your Manifest file and also make the hardwareAccelerated attribute of application tag to true. Check the sample code given below:

<application
    android:name=".MyApplication"
    android:hardwareAccelerated="true"
    ..

    <activity
        android:name="com.inmobi.rendering.InMobiAdActivity"
        android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
        android:resizeableActivity="false"
        android:hardwareAccelerated="true"
        android:theme="@android:style/Theme.NoTitleBar"
        tools:ignore="UnusedAttribute" />

</application

Step 3:

Add a ViewGroup in your layout so that we can add the InMobiBanner view within that view.

<RelativeLayout
    android:id="@+id/banner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center" />

Step 4:

Now add the below Java code in your Activity or Fragment to initialize and load the InMobiBanner ad.

InMobiBanner bannerAd = new InMobiBanner(this, 1234567890L);
RelativeLayout adContainer = findViewById(R.id.banner);
float density = getResources().getDisplayMetrics().density;
RelativeLayout.LayoutParams bannerLp = new RelativeLayout.LayoutParams((int) (320 * density), (int) (50 * density));
adContainer.addView(bannerAd, bannerLp);
bannerAd.load();

Hope this helps.

Upvotes: 8

Ulearn
Ulearn

Reputation: 189

Also, you need to add these line android manifest file

 <activity
        android:name="com.inmobi.rendering.InMobiAdActivity"
        android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
        android:resizeableActivity="false"
        android:hardwareAccelerated="true"
        android:theme="@android:style/Theme.NoTitleBar"
        tools:ignore="UnusedAttribute"/>

Upvotes: 0

digiwizkid
digiwizkid

Reputation: 811

You need to create the InMobiBanner class instance inside UI Thread as it is not thread-safe.

Official documentation says -

Notes:

  • The InMobiBanner class is not thread-safe. A banner instance must be created on the UI thread.

  • Similarly, all methods on this instance must be called on the UI thread. Not doing so will lead to unpredictable behavior and may affect your ability to monetize with InMobi.

Hope this answer your question. Thanks

Upvotes: 0

Related Questions