Leadbolt App墙无法正常工作

时间:2014-03-02 15:15:22

标签: java android leadbolt main-activity

我试图将Leadbolt“App wall”添加到我的内容中,但它没有显示。

我是按照文档解释的那样做的。

继承我的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(); 
} 
}

如果有人知道这个问题,请告诉我

提前致谢

PS:我是Java / android开发初学者。这是我的第一个项目。 对不起我来自德国的英语:)

1 个答案:

答案 0 :(得分:1)

很少有事情需要注意:

  • 在您的onCreate()中,您没有初始化您的AdController
  • 另一方面,onCreate11()onCreate1()从未被调用,因为这些不是活动生命周期方法
  • 同样适用于onDestroy1(),无论你在那里做什么,都不会被调用,因为onDestroy1()不是Activity生命周期方法
  • 除非为此帖子编辑此内容,否则MY_LB_AUDIO_ID,MY ID,APPFIREWORKS_API_KEY应为有效字符串,您可以从LeadBolt信息中心获取

你需要做什么:

1.您应该在onCreate()中初始化AdController,在创建Activity时调用它,因此将代码从onCreate11()或onCreate1()移动到onCreate()

<强> 2。你的清理代码可以在onDestroy()中,所以将它从onDestroy1()移到onDestroy()

第3。确保您的MY_LB_AUDIO_ID,APPFIREWORKS_API_KEY和我的ID是有效的字符串。

有关活动和生命周期的更多信息hereherehere