0

I tried to add the Leadbolt "App wall" into my but its not showing.

I did it like the documentation explains it.

Heres my MainActivity.java

package com.NAME.APP;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.NAME.APP.R;
import com.SDKPACKAGE.AdController; 
import com.appfireworks.android.track.AppTracker;
import android.content.Context; 
import android.content.Intent; 
import com.SDKPACKAGE.AdBootReceiver; 

public class MainActivity extends Activity {
/** Called when the activity is first created. */

public class BootReceiver extends AdBootReceiver { 
    public void onReceive(Context ctx, Intent intent) { 
        intent.putExtra("sectionid","MY ID"); 
        super.onReceive(ctx, intent); 
    } 
}    

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); //Set the screen's view to your xml file     

    Button button1 = (Button) findViewById(R.id.button1); // Retrieve the button from the XML file
    button1.setOnClickListener(new View.OnClickListener() {  //Add a listener for when the button is pressed
        @Override
        public void onClick(View v) {
            sendToTwitter();                       
        }
    });
}

protected void sendToTwitter() {
    String url = "MY URL"; // You could have this at the top of the class as a constant, or pass it in as a method variable, if you wish to send to multiple websites
    Intent i = new Intent(Intent.ACTION_VIEW); // Create a new intent - stating you want to 'view something'
    i.setData(Uri.parse(url));  // Add the url data (allowing android to realise you want to open the browser)
    startActivity(i); // Go go go!
}

private AdController ad; 

public void onCreate11(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    ad = new AdController(this, "MY ID"); 
    ad.loadStartAd("MY_LB_AUDIO_ID", "MY ID"); 
    AppTracker.startSession(this, "APPFIREWORKS_API_KEY"); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    if(ad != null) { 
        ad.destroyAd(); 
    } 
    if(!isFinishing()) { 
        AppTracker.pause(getApplicationContext()); 
    } 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    AppTracker.resume(getApplicationContext()); 
}         

public void onDestroy1() { 
    super.onDestroy(); 
    if(ad != null) { 
        ad.destroyAd(); 
    } 
    AppTracker.closeSession(getApplicationContext(),true);       
} 

@SuppressWarnings("unused")
private AdController ad1; 

public void onCreate1(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 

    ad = new AdController(this, "ID"); 
    ad.loadAd(); 
} 

public void onDestroy() { 
    ad.destroyAd(); 
    super.onDestroy(); 
} 
}

If anyone know the problem please let me know

Thanks in advance

PS: Im a Java / android development beginner. Thats my first project. And sorry for my English im from Germany :)

Melquiades
  • 8,496
  • 1
  • 31
  • 46
Rajat
  • 47
  • 2
  • 9

1 Answers1

1

Few things to notice:

  • in your onCreate(), you're not initializing your AdController
  • you have onCreate11() and onCreate1() on the other hand, which are never called, as these are not Activity lifecycle methods
  • the same goes for onDestroy1(), whatever you're doing there, is never called, because onDestroy1() is NOT Activity lifecycle method
  • unless this is edited for the purpose of this post, MY_LB_AUDIO_ID, MY ID, APPFIREWORKS_API_KEY should be valid strings, which you can get from your LeadBolt dashboard

What you have to do:

1.You should initialize your AdController in onCreate(), which gets called when Activity is created, so move the code from onCreate11() or onCreate1() to onCreate()

2. Your cleanup code can be in onDestroy(), so move it from onDestroy1() to onDestroy()

3. Make sure your MY_LB_AUDIO_ID, APPFIREWORKS_API_KEY and MY ID are valid strings.

More about activities and lifecycles here, here and here.

Melquiades
  • 8,496
  • 1
  • 31
  • 46
  • in onCreate() is my button intialized. i cant rename onCreate1 to onCreate() i get error message: Duplicate method onCreate(Bundle) in type MainActivity – Rajat Mar 02 '14 at 18:52
  • You can have only one onCreate(). Initialize your button there, AND also your AdController, as you're doing now in onCreate11() and onCreate1(). Just move that code to onCreate(), and delete onCreate11() and onCreate1(). Please read my answer again. – Melquiades Mar 02 '14 at 19:10
  • I got it working now thx. But i removed my button for that. Can i initialize both (Button and Ads) in one activity or do i have to create an another activity for the button? – Rajat Mar 02 '14 at 19:33
  • Yes, you can initialize both button and Ads in onCreate(). – Melquiades Mar 02 '14 at 19:41
  • Hey man Thanks for everything. I got it working. Ur my hero! :) – Rajat Mar 04 '14 at 20:42