In a Unity3D - Android project .. how to get memory warnings? - android

How to be alerted of memory warnings? Unity3D, building to Android.
Cheers.

You can subscribe to Application.lowMemory Documentation
For example, in some monoBehaviour starting your game:
private void Start()
{
Application.lowMemory += ReportSystemLowMemory;
}
private void ReportSystemLowMemory()
{
Debug.LogWarning("Warning: Low memory");
}
Be sure to don't subscribe ReportSystemLowMemory more than once.
Also unsubscribing it would be a good practice, ie Application.lowMemory -= ReportSystemLowMemory when you are close your app/game.

There is no inbuilt function for this in Android as far as I know.

Related

Firebase Database for Unity3d Android ValueChanged unsubscribe issues

I have problem with Unity3d SDK.
I subscribe to ValueChanged event and when first time it invokes I unsubscribe from the handler.
In Unity everything works fine.
But when I build project for Android, unsubscribe fails: after unsubscribe I still handle events in handler.
Here is the code:
public void CheckUserExists()
{
FirebaseDatabase.DefaultInstance
.GetReference("users").Child(primary_key)
.ValueChanged += CheckUserExistsHadler;
}
void CheckUserExistsHadler(object sender, ValueChangedEventArgs e)
{
FirebaseDatabase.DefaultInstance
.GetReference("users").Child(primary_key)
.ValueChanged -= CheckUserExistsHadler;
if (e.Snapshot == null || e.Snapshot.Value == null)
{
print("user_exists");
}
else
{
print("user_not_exists");
}
}
Thanks for the tip. I changed to
user_reference = FirebaseDatabase.DefaultInstance.GetReference("users").Child(primary_key);
...
user_reference.ValueChanged += CheckUserExistsHadler;
...
user_reference.ValueChanged -= CheckUserExistsHadler;
and it works fine
I Just ran into this issue on Android, worked in Editor.
What I found was that when I re-created the database reference at the point of un-subscribing, using the exact same reference string as I used to add the listener it would not properly un-subscribe in Android.
The solution I used was the same as Bestlis above, I created a DatabaseReference variable, which I used to sub and un-sub from, now it works.
It's an odd problem to have, it's like FirebaseDatabase.DefaultInstance.GetReference changes during operation?
For some reason, any firebase calls made from a callback fail(Getvalue, updatechildren, subscribe/unsubscribe, all that). Your best bet is to have it put into an action queue, and have a monobehavior check the queue/list and call its contents from the main thread.

Cocos2d-X 3 Memory Management

I am currently migrating I game I made in Cocos2d-X 2.2.6 to the latest version: Cocos2d-X 3.10, however I have a question about the memory management: I have created a lot of my own classes that inherit from CCObject (I have used a lot of XX::create(), xx->retain() and xx->release() methods to create and destroy objects), however since this class has been deprecated, what should I use in its place?
I guess my question is how can I do the memory management of a custom class in Cocos2d-X version 3?
I'm developing cocos2d-x games now.
As Mr.Zen commented, your class should inherit from cocos2d::Ref.
And member variables, use cocos2d::RefPtr.
It makes memory management easier, manages reference count automatically.
You don't need to worry about retain or release after the instance created.
Here is the snippet.
Sample.h
class Sample : public cocos2d::Ref
{
public:
Sample();
~Sample();
void hoge();
}
UseSample.h
class UseSample : public cocos2d::Ref
{
private:
cocos2d::RefPtr<Sample> sample { nullptr };
void createSample();
void useSample();
}
UseSample.cpp
void UseSample::createSample()
{
this->sample = Sample::create(); // RefPtr increases sample retain count;
}
void UseSample::useSample()
{
this->sample->hoge();
}
Hope this can helps.

Unity3D getting errors without console - android build

I want to check exceptions and errors in my game in built up, but there is no debug console in game so I want to make one. Is there any way to get those errors from original console and write it on screen?
You can add a callback function to Application.logMessageReceived to receive the Debug.* messages. For example:
void Awake(){
Application.logMessageReceived += HandleLog;
}
private void HandleLog(string logString, string stackTrace, LogType type) {
// add them to some UI component for visualizing
}

Chartboost Interstitial won't show Ads on Unity

Lately, I have been trying to add static interstitial ads into my Unity game. For some reason, I could not get the system to show anything, or even react to me. After trying to work with the base Chartboost plugin, I tried to match a tutorial that I was following and purchased Prime31's Chartboost plugin and have been using that. However, neither the base plugin, nor Prime31's plugin, seem to be allowing me to show any ads. The code is pretty much done inside a single object, and it seems simple enough.
public class Advertisement : MonoBehaviour {
public string chartboostAppID = "5461129ec909a61e38b1505b";
public string chartboostAppSignature = "672b3b34e3e358e7a003789ddc36bd2bc49ea3b5";
// Use this for initialization
void Start () {
DontDestroyOnLoad(this.gameObject);
ChartboostAndroid.init (chartboostAppID, chartboostAppSignature, true);
ChartboostAndroid.cacheInterstitial(null);
}
void OnLevelWasLoaded(int level) {
ChartboostAndroid.cacheInterstitial(null);
if(Application.loadedLevelName == "Network Lobby") {
showAds();
}
}
public static void showAds() {
Debug.Log("Showing ad");
ChartboostAndroid.showInterstitial(null);
}
}
As you can see, it's pretty straightforward. This object is created at the game's splash screen, which appears only once, and it's never destroyed until the program ends. The goal is, whenever I enter the lobby scene, I want to see an ad before going to the lobby's menus. As it is, I do see the log printing "Showing ad", so I know the function is being called. However, nothing appears. Do I need to disable the GUI system first? Is there a step I'm missing?
I have already performed the following steps:
I have created and registered the app with chartboost, as well as double and triple checked the AppID and App Signature.
I have created a publishing campaign and registered it to the app.
I double-checked the orientation and confirmed that it's correct.
I registered this specific device as a test device.
The tutorial showed a call to ChartBoostAndroid.OnStart(), but there was no function like that for me to call. Perhaps that is from an older version?
I emailed Chartboost support and have not heard from them yet. I do not have that much time on this project, so if anyone can offer help, I'd appreciate it.

Monitoring errors with Sentry - Android

I need to implement Sentry for my android app, I try to find an example about how I have to implement this, but I can't find it.
I saw the Sentry documentation in http://sentry.readthedocs.org/en/latest/developer/client/index.html#server_name
But I have some questions.
If my app crash, the exception will be captured?
Should I put this code line into my try/catch?
var $resultId = myClient->captureException($myException); (in android code)
If somebody has a sample in android I will be grateful.
Thank you!
I am a little late but I just recently released a Sentry client for Android. It's in its early stages so feel free to pull request any changes that you see.
https://github.com/joshdholtz/Sentry-Android
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Sentry will look for uncaught exceptions from previous runs and send them
Sentry.init(this, "YOUR-SENTRY-DSN");
}
}
Maybe try using something like BugSense? http://www.bugsense.com/
If it definitely has to be Sentry, then look at this example: https://stackoverflow.com/a/755151/349012
It shows you how to set your own uncaught exception handler so you can try and upload to Sentry.

Categories

Resources