2014-04-02 40 views
1

我們正在使用我們的應用程序之一的應用程序遊戲套件,並試圖刪除AdMob,因此我們可以使用Chartboost。 AGK使用解釋器作爲他們通過NDK傳遞給java的語言。 他們有一個名爲AGKHelper的類,它是目前稱爲Facebook,AdMob,警報對話和其他一些活動的命令的入口點。 AGKHelper中的每種方法都通過Runnable類運行事件。下面是他們的過程的實例,使警報對話:Android RunOnUIThread用於AGK AppGameKit的Chartboost SDK集成NDK

public class AGKHelper { 
    //just a sample of what's in there many other methods exist 
    public static void ShowMessage(Activity act, String msg) 
    { 
     RunnableMessage run = new RunnableMessage(); 
     run.act = act; 
     run.msg = msg; 
     act.runOnUiThread(run); 
    } 

} 

現在RunnableMessage類創建警報對話。

class RunnableMessage implements Runnable 
{ 
    public Activity act; 
    public String msg; 

    public void run() { 
      AlertDialog alertDialog; 
      alertDialog = new AlertDialog.Builder(act).create(); 
      alertDialog.setTitle("Message"); 
      alertDialog.setMessage(msg); 
      alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialog, int which) {}}); 
      alertDialog.show(); 
      } 
} 

還存在一個CreateAd()方法,使廣告的AdMob使用runOnUiThread(),但有WindowManager以顯示廣告。 據我們所知,我們必須使用Runnable來獲取Chartboost的活動。 我們遵循Chartboost的SDK集成,因此我們無法爲其創建RunnableAGKHelper所使用的所有Runnables也參考NativeActivity,我們認爲它將它作爲參數傳遞給ShowMessage()之類的方法,然後在Runnable類中爲其中的每個方法執行一些操作。如

AlertDialog.Builder(act) //for the message 
ad = new AdView(act, AdSize.BANNER, pubID); //for AdMob - RunnableAd 
feed.dialog(act, "feed", parameters,new DialogListener() {} // for RunnableFacebook 

遺憾的是,似乎沒有要傳遞NativeActivity到Chartboost可運行的方式。我們對java很缺乏經驗,所以我們正在學習,並且感覺我們正在取得進展,但沒有任何反應。

有沒有人有得到Chartboost顯示的Runnable類的完整示例?我們非常感謝幫助。 我會在這裏分享更多的AGKHelper類,例如完整的RunnableAd()方法,但它很長並且填充了WindowsManager設置。 RunnableMessage是我可以提供的最短例子。謝謝。

回答

0

我們已經能夠通過IntentstartActivity()得到這個運行。

AGKHelper類,這是爲切入點所有命令包含:

public static void CreateAd(Activity act, String publisherID, int horz, int vert, int offsetX, int offsetY) 
{  
    Looper.prepare(); 

    Intent myIntent = new Intent(act, ChartboostActivity.class); 
    act.startActivity(myIntent); 
} 

ChartboostActivity類:

public class ChartboostActivity extends Activity { 
    private Chartboost cb; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.chartboostmain); 
     //requestWindowFeature(Window.FEATURE_NO_TITLE); 

     // Configure Chartboost 
     this.cb = Chartboost.sharedChartboost(); 

     String appId = "XXXXXXXXXXXXXX"; 
     String appSignature = "XXXXXXXXXXXXXXX"; 
     this.cb.onCreate(this, appId, appSignature, null); 
     //this.cb.setImpressionsUseActivities(true); 
     CBPreferences.getInstance().setImpressionsUseActivities(true); 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 
     this.cb.onStart(this); 
     // Notify the beginning of a user session. Must not be dependent on user actions or any prior network requests. 
     this.cb.startSession(); 
     // Show an interstitial 
     //this.cb.showInterstitial(); 
     this.cb.showMoreApps(); 
     finish(); 
    } 

    @Override 
    protected void onStop() { 
     //finish(); 
     super.onStop(); 

     this.cb.onStop(this); 
    } 

    @Override 
    protected void onDestroy() {   
     //finish(); 
     super.onDestroy(); 

     this.cb.onDestroy(this); 
    } 

    @Override 
    public void onBackPressed() { 
     // If an interstitial is on screen, close it. Otherwise continue as normal. 
     if (this.cb.onBackPressed()) 
     { 
      finish(); 
      return; 
     } 
     else  
      super.onBackPressed(); 
    } 
} 

雖然這看起來工作得很好,我們覺得很奇怪,我們不能使用finish()關閉onDestroy()onStop()中的循環。理想情況下,我們希望在Runnable類中完成所有這些操作,以便我們可以訪問該活動並可以調用其他方法。如果有人有這樣的例子,將不勝感激。但是這個解決方案似乎可行!