We've been able to get this running with Intent
and startActivity()
.
AGKHelper
class which is the entry point for all commands contains:
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
class:
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();
}
}
While this seems to work just fine we found it strange that we couldn't use finish()
to close the loop in onDestroy()
or onStop()
. Ideally we'd like to do all of this in a Runnable
class so that we have access to the activity and can call other methods. If anyone has an example of that it would be greatly appreciated. But this solution appears to work!