AdMob with LibGDX 1.2.0 Memory Leak - android

I'm new to Libgdx and also to AdMob. Recently I've been trying to get both to work together. How ever everytime when I start the app on my device over Eclipse it just does nothing and after a time my notebook is so slow, I'm guessing that there is a memory leak.
I've checked all official and unofficial tutorials and even notes and codes on github of libgdx and other people but I just can't find a clue why it wouldn't work.
Is there anybody out there having running example codes of the newest Libgdx (1.2.0) with the newest AdMob?
So this is what I have, note: I left BANNER_ID and TEST_ID out.
package com.samynoname.treasurebox.android;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.samynoname.treasurebox.TreasureBox;
public class AndroidLauncher extends AndroidApplication {
private static final String BANNER_ID = "MY ID";
private static final String TEST_DEVICE_ID = "TEST ID";
protected AdRequest requestAd;
protected AdView bannerAd;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
FrameLayout layout = new FrameLayout(this);
TreasureBox game = new TreasureBox();
View gameView = initializeForView(game, config);
requestAd = new AdRequest.Builder().addTestDevice(TEST_DEVICE_ID).build();
bannerAd = new AdView(this);
bannerAd.setAdSize(AdSize.BANNER);
bannerAd.setAdUnitId(BANNER_ID);
bannerAd.loadAd(requestAd);
bannerAd.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.TOP));
layout.addView(gameView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
layout.addView(bannerAd);
setContentView(layout);
}
}
And this is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samynoname.treasurebox.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.samynoname.treasurebox.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<!-- Google play services -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- Google play Admobs -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
I'm really really thankful for any notes!

Wow... after such a long time I finally found an answer.
The answer is described here in further details:
https://stackoverflow.com/a/6024262/2896954
It seems like Eclipse was lacking memory to build the project.

Related

Android + Phonegap + Parse Push keeps crashing

I've been trying to make a simple Phonegap app that receives Parse Push notifications on Android.
I've read a number of tutorials and read through related issues here and elsewhere but i can't seem to get it to work without crashing.
I have the latest of Java JDK, Cordova + Node JS + plugman, Android API 19 (seems to be required by cordova), Apache ant, etc...
Bottom line: I can start the app. I can receive the notification just fine. But when I tap the notification to go back to the app it always crashes.
Question? Can anyone explain why this is happening? Or even better if you have a sample project that works? Any help would be greatly appreciated.
References:
https://parse.com/tutorials/android-push-notifications
http://www.raymondcamden.com/2012/10/10/PhoneGap-Parsecom-and-Push-Notifications -- a bit out of date
How do I get Parse.com Push Notifications working in a Cordova/Phonegap Android app?
apache cordova app crashes after receiving parse.com push notification
Sources:
AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.company.challenger" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.company.challenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.challenger.permission.C2D_MESSAGE" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name" android:name="com.company.challenger.ChallengerApplication">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/app_name" android:launchMode="singleTop" android:name="ChallengerApplication" android:theme="#android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.company.challenger" />
</intent-filter>
</receiver>
<receiver android:exported="false" android:name="com.parse.ParsePushBroadcastReceiver">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
CordovaApp.java
package com.company.challenger;
import com.parse.ParseAnalytics;
import android.os.Bundle;
import org.apache.cordova.*;
public class CordovaApp extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
ParseAnalytics.trackAppOpened(getIntent());
}
}
ChallengerApplication.java
package com.company.challenger;
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
import com.company.challenger.CordovaApp;
public class ChallengerApplication extends Application
{
private static ChallengerApplication instance = new ChallengerApplication();
public ChallengerApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
#Override
public void onCreate() {
super.onCreate();
// register device for parse
Parse.initialize(this, "app key", "client key");
PushService.setDefaultPushCallback(this, CordovaApp.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Proper answer this time...
I basically started from scratch following the latest parse tutorial and making sure the initialize parse in the MainApplication and not in your javascript.
This is the gist:
Create a MainApplication.java with a skeleton like this:
package com.{your_company}.{your_app};
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParsePush;
import com.parse.SaveCallback;
import com.parse.ParseException;
import com.{your_company}.{your_app}.MainActivity;
public class MainApplication extends Application
{
#Override
public void onCreate() {
super.onCreate();
// parse initialization goes here
}
}
Add the following attribute to your application tag in AndroidManifest.xml
<application ... android:name="com.{your_company}.{your_app}.MainApplication">
Follow this tutorial from Parse.com which is fairly decent https://parse.com/tutorials/android-push-notifications .
The final onCreate in MainApplication.java should look something like this:
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(app);
Parse.initialize(app, "{app_key}", "{client_key}");
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
From this experience I found the following insights:
Not recommended to use any parse push plugins floating around because
there are all out of date using deprecated calls or simply did not
work out of the box.
The Parse initialize must occur in the MainApplication and cannot occur in the javascript. (I don't have the reference for this one, I came
across it somewhere down the line when frantically researching).
Always use the latest Parse SDK and use ParsePush (the new service) and not PushService which is depricated.
Hopefully this helps.

can't display Openstreetmap

I want to display a part of a OSM but i don't know what's the problem with my code, when I run it, the map didn't display:
No error appear but the map didn't only display! I work with eclipse and the emulator Google API 8!
here is my MainActivity code:
package com.formation.dsmap1;
import org.mapsforge.android.maps.MapActivity;
import org.mapsforge.android.maps.MapView;
import android.annotation.SuppressLint;
//import android.annotation.SuppressLint;
//import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
//import android.os.Environment;
public class MainActivity extends MapActivity {
// #SuppressLint("SdCardPath")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapView mapView = new MapView(this);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setEnabled(true);
// mapView.setMapFile("/sdcard/essai.jpg");
// setContentView(mapView);
mapView.setMapFile(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "essai.osm");
setContentView(mapView);
}
}
and my AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.formation.dsmap1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.formation.dsmap1.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Can you help me please?
add this permission to your manifest and will be fine :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Adding Shared Library Project Android

I'm struggling with adding a library to my project. I've been following a few other SOs as well as the tictactoemain/lib sample Android provides, but I'm still getting a "unable to find explicit activity class" error. The library package I included showing up under Android Dependencies is com.example.surveymetest. I suspect the issue is how I'm calling/defining the activity in the manifest but I can't seem to get it right. Any ideas where I'm going wrong?
Here's my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.surveymedemo.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.surveymetest.SurveyActivity"
android:label="#string/app_name" >
</activity>
<activity android:name="com.example.surveymetest.TakeSurveyActivity" >
</activity>
<provider
android:name="com.example.surveymetest.SurveyMeContentProvider"
android:authorities="io.surveyme.ContentProviders.SurveyMeContentProvider"
android:exported="true" >
</provider>
</application>
</manifest>
Calling the Activity:
package com.example.surveymedemo;
import com.example.surveymetest.StartSurveyActivity;
import com.example.surveymetest.SurveyMe;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this, StartSurveyActivity.class);
startActivity(i);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Add:
<activity
android:name="com.example.surveymetest.StartSurveyActivity"
android:label="#string/app_name" >
</activity>
to your manifest and you should be good.
(you only defined com.example.surveymetest.SurveyActivity)

Integrating AdMob through Google Play Services with Unity 3D

Following this tutorial I started working on integrating AdMob into Unity, but as this uses an older version I had to make some changes to update it to the Google Play Services version, but I think I may have messed up.
I imported all the required libraries into both Unity 3D's Plugins/Android and Eclipse's Java Build Path and Order and Export.
Every time I call the script in Unity the game crashes and LogCat says it had an error with a tag "AndroidRuntime" "at admob.admob$1.run(admob.java:52) which is this line
adView.loadAd(adRequest);
Here's my AdMobController.js from Unity:
#pragma strict
public class AdMobController extends MonoBehaviour {
private static var s_Controller : AdMobController;
private static var jo:AndroidJavaObject;
function Awake()
{
s_Controller = this;
#if UNITY_ANDROID
jo = new AndroidJavaObject("admob.admob");
#endif
}
}
File admob.java
package admob;
import com.google.android.gms.ads.*;
import com.unity3d.player.UnityPlayer;
import android.app.Activity;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
public class admob{
// private String pubID = "ADMOB_ID_HERE"; //Your public AdMob ID. Make sure this is correct, or you won't get any credit for the Ad.
private Activity activity; //Store the android main activity
private AdView adView; //The AdView we will display to the user
private LinearLayout layout; //The layout the AdView will sit on
//Constructor
public admob() {
activity = UnityPlayer.currentActivity;
activity.runOnUiThread(new Runnable() {
public void run() {
/*
layout = new LinearLayout(activity);
activity.addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
adView = new AdView(activity);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(pubID);
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adView.loadAd(adRequestBuilder.build());
*/
layout = new LinearLayout(activity);
// Create the adView.
adView = new AdView(activity);
adView.setAdUnitId("MY_AD_ID"); //Yes, I put the correct ID here. I only deleted it before posting here.
adView.setAdSize(AdSize.BANNER);
// Add the adView to it.
layout.addView(adView);
activity.addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // Emulator
.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") // Test phone. Not my actual phone because I could
// not call AdRequest to get the ID for it.
.build();
// Load the adView with the ad request.
Log.d("unity321", "unity321");
adView.loadAd(adRequest);
layout.addView(adView.getRootView(), new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
// Code in here will run on the UI thread of this application
}
});
}
}
AdMob manifest from Eclipse:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.admob.admob"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
And finally the manifest in the plugins folder in Unity used to override the Unity built manifest (NOTE: android:value="google_play_services_version" is changed because with the #integer/ both Unity and Eclipse said no value was found and would not export)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TESTCOMPANY.TESTAPP"
android:theme="#android:style/Theme.NoTitleBar"
android:versionName="1.0"
android:versionCode="1"
android:installLocation="auto">
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
<application android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape"
android:launchMode="singleTask"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity"
android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik"
android:value="true" />
<meta-data android:name="com.google.android.gms.version"
android:value="google_play_services_version"/>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.sensor.accelerometer" />
<uses-feature android:name="android.hardware.touchscreen" />
<uses-feature android:name="android.hardware.touchscreen.multitouch"
android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct"
android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Yep, this is what I did.
Make another folder in unity; where your plugins are.
Mine is Assets/plugins/android/
You need Assets/plugins/android/res/values
In the values folder save this in an xml file named values.xml
<?xml version="1.0" encoding="UTF-8"?>
-<resources>
<integer name="google_play_services_version">4132500</integer>
</resources>
Copy the folder google_play_services from <Android sdk>/extras/google/ to the Assets/Plugins/Android folder in Unity and build the project again.

Unable to instantiate activity ComponentInfo java.lang.ClassNotFoundException: util.kalyan.HelloGoogleMapsActivity

I have included all the necessary fields correctly.
But still, I am not able to launch the Google map on my emulator.
Checked the internet permissions also.
Getting error like:
E/AndroidRuntime(2064): java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{util.kalyan/util.kalyan.HelloGoogleMapsActivity}:
java.lang.ClassNotFoundException: util.kalyan.HelloGoogleMapsActivity
Please find below my code.
HelloGoogleMapsActivity.java
package util.kalyan;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import util.kalyan.R;
public class HelloGoogleMapsActivity extends MapActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="util.kalyan"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<uses-library android:name="com.google.android.maps"></uses-library>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" >
<activity android:name=".HelloGoogleMapsActivity" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses- permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Any one please help me in this at the earliest.
Thanks in advance.
Change the android:name in activity definition
from
<activity android:name=".HelloGoogleMapsActivity" ../>
to
<activity android:name="util.kalyan.HelloGoogleMapsActivity" ../>
You emulator target should be one that includes Google APIs (Google Inc.).
Right click on your HelloGoogleMapsActivity class > BuildPath > Exclude Then Right click on your HelloGoogleMapsActivity class > BuildPath > Include your class again

Categories

Resources