I have created an app in Sencha Touch 2 with GCM plugin. Everything working fine with push notification but when clearing notification, its killing app.
I have no idea of java, but still tried to fork GCM java code but didn't got any success by the solutions found after googling around,
Few solution(google gave ;) ) tried but no success:
- ExceptionHandling
- onResume() function
After researching lot, found onResume isn't getting even called and app is killed much before. I dont know how to debug it. Using cordova to build & webstorm IDE.
Some saying less memory space might kill app but after testing on many devices found memeory isn't the issue.
Plz help me out as already wasted much time on it.
Not sure exactly what is wrong here, but as per you mentioned I am guessing the problem is with the handling of the event when the notification is clicked in order to open the subsequent activity. Please have a look at this code.
#Override
protected void onHandleIntent(Intent intent) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, LoginActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("New Message!");
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
}
Please make sure you implement the onHandleIntent() method after the notification is tapped so that it opens the activity where it should actually be.
Related
I created an app using Xamarin.Forms. I am trying to detect if there is a change in phone's language each time the app is reopened after being closed using the back button. Tried to Debug.WriteLine on each of onStart, onSleep and onResume to see which one occurs when I open the app again but none of them worked. This is what i tried:
App.xaml.cs
protected override void OnStart()
{
Debug.WriteLine("onresume");
//CultureInfo language = CultureInfo.InstalledUICulture;
//Thread.CurrentThread.CurrentUICulture = language;
//ApplicationResource.Culture = language;
//Application.Current.MainPage = new NavigationPage(new MainPage());
}
protected override void OnSleep()
{
Debug.WriteLine("onsleep");
}
protected override void OnResume()
{
Debug.WriteLine("onresume");
}
How do I know when the app is reopened so I could try the language change code?
If i understand your concern correctly two things can help you:
On android you can have a very wierd behavour if you do not specify SingleTask for your mainactivty. Basically if you "close" the app using Back button and then click on app icon, the app is launched from start recreating App but keeps static variables and the debugger is still connected too. You can detect it setting a static variable, then checking it with a breakpoint inside App.cs constructor. So the avoid such just use LaunchMode = LaunchMode.SingleTask inside the MainActivity.cs [Activity] attribute. This way after you return to the app after the Back button + click on icon you'll get a fresh new app with OnStart invoked.
Some could say to use LaunchMode.SingleInstance but it will kill your app if you click on push notification whie app is active so better use SingleTask, it will open smoothly the running app.
To store and retrieve data between app launches use local persistent storage, full docs: https://learn.microsoft.com/en-us/xamarin/essentials/preferences?tabs=android. So when you got your language store it, then at app start (App.cs constructor) check values.
I had done a simple to test your code with the Android simulator. And I use the Console.WriteLine instead of the Debug.WriteLine.
I had found that:
When the app exited with the back button, it will call the OnSleep method and if you get into the app in the recent task, it will call the OnStart method.
When the app go to background with the home button, it will call the OnSleep methed too, but if you get into the app in the recent task, it will call the OnResume method.
So if you add a break point in the OnStart method, when you exit with the back button and get into the app again, it will hit the break point.
Firebase dynamic links are working well both after installation and whenever the app is in the background.
However, if it's coming from the inactive state (app is closed), it doesn't work. Both applicationOpenURL and applicationUserActivity is not being called.
Anybody experienced this before? I've been trying to solve this for days now, back and forth with Firebase's tutorial. I'm sure I'm just missing something here.
Put this in didFinishLaunchingWithOptions
//Handle dynamic links when app is CLOSED
let activityDic = launchOptions?[.userActivityDictionary]
if let isActivityDic = activityDic {
// Continue activity here
return true
}
it will call continue userActivity if the app is opened from CLOSED state.
So, I had a working xamarin forms app that used azure mobile services. I upgraded the server side to use mobile app service and upgraded the nugets in my client to use the latest and greatest client codes.
I manually updated my test/ios simulator sqlite db to use the proper column names for the system properties since they dropped the double underscore prefix.
When I finally got it all built and tried to run in the ios 6/8.3 simulator it ran fine until it hit the InitializeAsync method. It doesn't throw (its in a try catch) and I let it run for a long time and it just sits there.
I then tried to change the db name so it would make it from scratch, which it did but still just hung. So I then tried to simplify it to a single table and took out my delegating handler so it was as basic as I could get it and it still just hangs.
Has anyone else had this problem? I am at a complete loss because I don't get an error. Not sure where to start.
Thanks.
Edit, code added:
var store = new MobileServiceSQLiteStore(_localDatabaseName);
store.DefineTable<Profile>();
try
{
await _mobileService.SyncContext.InitializeAsync(store);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
I also tried with ConfigureAwait(false) as suggested but it made no difference.
I set breakpoints in the catch and the code that immediately follows this block but they are never hit.
Ok, so I poked around a bit more and found some info on deadlocked threads answered by Stephen Cleary, the guru of async/await.
It turned me onto looking upstream. The call into my azure init code looked like this:
var azureService = Container.Get<IAzureService>();
azureService.InitializeAzync().Wait();
Which was in the constructor of the calling component.
So, I changed it to this:
try
{
Task.Run(() => azureService.InitializeAsync()).Wait();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
And the SyncContext.InitializeAsync() call worked fine and continued on.
So, I don't really know the answer for this, I guess the internals of the new azure client do something differently than the old code since using Wait() was how I did it before and never had a problem. But there was some sort of threading deadlock. Very odd and took days to get past, now I have to fix the next deadlock I hit. If Stephen is out there and can offer some clarification that would be great.
Had this same issue - changing to a Task.Run and ConfigureAwait(false) did fix it.
Very odd thing is the same code worked fine with Mobile Services, but broke when we upgraded to Mobile App Services.
I am coding a text based web browser game in ASP.NET. But i need a lil bit info so i decided to ask here.
When user enter any quest, lets say that quest take 10 mins to proceed. If user exits from game, how can i make my script to run automaticly and finish the quests and upgrade players power etc? I heard something like CronJob. But i dont know if it works for ASP.NET so i wanna hear any idea before i do this. Thank you for your help.
You could just add a cache item with a callback function.
public void SomeMethod() {
var onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
Cache.Add("UserId_QuestId", "AnyValueYouMightNeed", null, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration, CacheItemPriority.High, onRemove);
}
public void RemovedCallback(String key, Object value, CacheItemRemovedReason r){
// Your code here
}
The cache item has an expiration of 10 minutes, and as soon as it is removed from memory the RemovedCallback will be invoked.
Note: just to completely answer your question:
You could also use some of the frameworks available to schedule tasks in asp.net (such as Quartz.net).
Create a Console project in your solution and schedule it on the Web server (using the Windows Scheduler).
Create a Web Job project, if you are deploying your web in Azure.
But in your situation, using the cache is probably the simplest solution.
I know I can manually go to status.firebase.com but I need to be alerted immediately when my firebase app goes down and when it comes back up.
I thought I could possibly use dingitsup.com to send myself a notification, but i don't know where to point it.
I would also like to have the option of automatically displaying a message to my users when Firebase is down to let them know the system is down and its not a problem on their end. Is there a Zapier integration i could use to achieve this?
Any help would be great! Thanks
Programmatically, you could use a service like Pingdom to send yourself a notification, and could ping an endpoint on your-firebase.firebaseio.com/some-public-endpoint.json.
Also, #FirebaseStatus is a good resource actively updated by the Firebase folks.
Could you write something to use the connection state?
https://www.firebase.com/docs/managing-presence.html (broken)
new link: https://firebase.google.com/docs/database/web/offline-capabilities
I use something similar in my apps to detect if the user has a connection, and display a notice if they don't.
I just figured a way
Firebase.enableLogging(function(logMessage) {
if(logMessage && logMessage.indexOf("Long-poll script failed to load") !== -1 && navigator.onLine){
console.error('Its dead Jim! Firebase seems to be down for this user');
}
});
I'm not sure how firebase works under the hoods but I've seen users connected in a previously open tab and if they open a new tab firebase won't connect when it's down.
This logging function is called a lot, and when firebase is down our console.error will be call every ~5s or something.
Make sure to debounce whatever you'll do in the console.error's place.