0

我试图将 Leadbolt“应用程序墙”添加到我的,但它没有显示。

我按照文档解释的方式进行了操作。

这是我的 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 开发初学者。那是我的第一个项目。对不起我来自德国的英语即时消息:)

4

1 回答 1

1

有几点需要注意:

  • 在你的onCreate(),你没有初始化你的 AdController
  • 另一方面,你有onCreate11(),它们从未被调用,因为它们不是 Activity 生命周期方法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 和 MY ID 是有效字符串。

有关活动和生命周期的更多信息,请点击此处此处此处

于 2014-03-02T15:43:37.443 回答