[Q] GPS-tracking acting weird. - Windows Phone 7 Q&A, Help & Troubleshooting

Hello!
Firstly, I don’t speak english very well. But I beg your indulgence.
I have some troubles with every GPS tracking apps I’ve installed on my Omnia W (I8350). While I start the tracking and locking my phone, it’s tracking quite well.
BUT, if I want to write a SMS or something. I have to press on the Windows-button to come out to the main menu, and the GPS-tracking will stop. But the time counter continues unaffected.
I think it’s a bit weird behavior. I have testet, Endomondo, Sports Tracker, SmartRunner, Runtastic. And all of these apps acts at same way.
Is this normally? Is it the OS, which stops the GPS-device, while the app is minimized?

It's the OS, yes. In theory, an app could continue GPS tracking in the background, but since that's not officially allowed (you'd need to mess with the APIs in ways Microsoft doesn't approve of) it wouldn't be allowed into the Marketplace.

@GoodDayToDie
Do you know any working hack that will allow app continue tracking in the background? Maybe some registry changing?
If app cannot get to Marketplace, it is not problem for me. I want to create GPS tracking in background only for myself.

At the max it will work with screen lock though Endomodo doesnt support but others do. And Yes its a problem with Windows Phone API not allowing intensive tasks to run in background.
May be a custom app can do which somebody can sideload but then its for one few people.

Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.

GoodDayToDie said:
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
Click to expand...
Click to collapse
I am pretty sure that just keeps it in memory, but not actually running. I downloaded the source code to see what it does and manually applied the registry change. It allows fast resume from any app, even if it was not recompiled for Mango. This is good for apps, such as Angry Birds, which would otherwise dehydrate, and need to restart. But, when using it, you can see that if you launch a bird, and then switch out. Wait a while. Then switch back to it. You can see that the launched bird has not moved since switching to a different app. It is possible that the app is suspending by responding to the fact that it is being pushed into the background.
Most apps that display time, or a timer that counts are not actually counting. What they do to display it get an initial time value when the timer starts. Then they get the time and subtract the initial time from it. So, an app that seems to count seconds, even when in the background is really just successfully get the current time and subtracting the original time before suspension. They may use a timer control to schedule the frequency that this calculation is made.
To verify, it would be good to test with a simple program that does something like:
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] TestCountApp
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]partial[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] : [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Form1()
{
InitializeComponent();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStart_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
timer1.Start();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] timer1_Tick([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] val = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] try
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
val = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Parse(tbText.Text.ToString());
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] catch[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ex)
{
}
i++;
tbText.Text = i.ToString();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStop_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
timer1.Stop();
}
}
}
of course the timer class might automatically suspend for Windows Phone.
So, a simple for loop might be better.
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] TestCountApp
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]partial[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] : [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Form1()
{
InitializeComponent();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStart_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] for[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0; i < 60; i++)
{
tbText.Text = i.ToString();
System.Threading.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Thread[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Sleep(1000);
}
}
[/SIZE][/FONT][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] }
}
If it is background processing, you should see 59, after returning to the app. It will remain blank until the end.
[/SIZE][/SIZE][/FONT][/FONT][/SIZE][/FONT][/SIZE][/FONT]

GoodDayToDie said:
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
Click to expand...
Click to collapse
Unfortunatelly it doesn't help, because OS is suspending app executing. OS is just keeping app in memory.
Anyway I can use background task in debug build with LaunchForTest method that will allow me execute background code as often I want. However background task cannot access fresh GPS data. It can only used cached data which is refreshed every 15 minutes. Is any way to force GPS to refresh it's data when using GPS from background agent?

OK, in reverse order:
@Mendoza32: You are quite incorrect; the change to the registry I was talking about actually causes the OS to *not* suspend apps. It can cause problems for some of them. In Mango, an app is *always* kept in memory when it's backgrounded. Apps that weren't recompiled for Mango can't take advantage of this and will do a full rehydrate anyhow, but they don't hve to (using a process listing, you can see that the suspended processes are still in memory). However, even with the tweak, a few things are cut off, like audio (and possibly GPS). See my response to JVH3 for more info...
As for a background agent, there's no official way. I think if you abuse one of the background audio decoder agent classes, you might be able to make an agent that runs in the background and can access the GPS. I haven't tried, though, and there's no chance of it getting into the Marketplace.
@JVH3: If you read the really old threads on the subject, you'll see that the app really does keep running in the background. For example, you can create an app that will pop a MessageBox (which always goes to the foreground) after 10 seconds, start it and immediately hit the Windows key. A few seconds later, you'll get the message box. More practically, you can use this hack to do things like run the WebServer app (any version) in the background, and browse it in the foreground on the phone's IE (pointing to 127.0.0.1). This would be impossible if the app were suspened, obviously...
As for Angry Birds, the game is in fact pausing the XNA update/render loop when notified that it's going into the background. In theory, this allows it to save the entire current game state, including the flying bird, such that when you resume the app (from dehydration, or so it thinks), that bird is exactly where it was and you've lost no progress. I suspect it is actually doing this. On the other hand, a game like Puzzle Quest 2 (which is rather poorly behaved regarding dehydration) quite obviously does *not* suspend the update/render loop. It's a turn-based game, so there is no gameplay problem, but there are certain real-time graphical effects that, when you "resume" the game, will all render simultaneously. Additionally, the phone will get quite warm and use a lot of battery (and other games will run slowly) because Puzzle Quest 2 still eating CPU and GPU time in the background.

GoodDayToDie said:
As for a background agent, there's no official way. I think if you abuse one of the background audio decoder agent classes, you might be able to make an agent that runs in the background and can access the GPS. I haven't tried, though, and there's no chance of it getting into the Marketplace.
Click to expand...
Click to collapse
I do not want put app in Marketplace. It's only for me
GoodDayToDie said:
@JVH3: If you read the really old threads on the subject, you'll see that the app really does keep running in the background. For example, you can create an app that will pop a MessageBox (which always goes to the foreground) after 10 seconds, start it and immediately hit the Windows key. A few seconds later, you'll get the message box.
Click to expand...
Click to collapse
Could you provide some sample code how to display this message box when app is in background? I tried this but without any luck. Maybe I'm missing something.

Did you have the no-suspend/dehydrate tweak enabled? It should be simple (event handler for a button or something:
Thread.Sleep(10000); MessageBox.Show("Alert from background app");

Thank you very much GoodDayToDie. I see how it works now. As long as GUI thread is blocked, then background threads keep working (also the GPS). One drawback is that I cannot go back to my app. It just keep displaying "Resuming...", but this is because GUI thread is blocked.

@GoodDayToDie
I was all wrong. Blocking GUI thread doesn't help in anything, because OS is killing app.
Please take a look at this sample code:
Code:
using System;
using System.Diagnostics;
using System.IO.IsolatedStorage;
using System.Threading;
using System.Windows;
using Microsoft.Phone.Controls;
namespace PhoneAppBackgroundTest
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
this.Loaded -= this.MainPage_Loaded;
this.DisplayLastUpdateTime();
}
private void buttonBackgroundThread_Click(object sender, RoutedEventArgs e)
{
ThreadPool.QueueUserWorkItem((s) =>
{
while (true)
{
this.UpdateLastUpdateTime();
Debug.WriteLine(DateTime.Now.ToString());
Thread.Sleep(1000);
}
});
}
private void buttonBlockGUIThread_Click(object sender, RoutedEventArgs e)
{
while (true)
{
Thread.Sleep(1000);
}
}
private string lastUpdateKey = "lastUpdate";
private void DisplayLastUpdateTime()
{
string value;
if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>(this.lastUpdateKey, out value))
{
MessageBox.Show("last update time: " + value);
}
}
private void UpdateLastUpdateTime()
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(this.lastUpdateKey))
IsolatedStorageSettings.ApplicationSettings.Remove(this.lastUpdateKey);
IsolatedStorageSettings.ApplicationSettings.Add(this.lastUpdateKey, DateTime.Now.ToString());
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
}
Button "buttonBackgroundThread" is starting new background thread which updates settings value and display current time to Output window. When you press this button you will see in Ouput, that current time is displaying each second. When you use window key, then current time is no longer displaying in Output. So the thread gets suspended. When you go back to app it start to work again.
When you press on button "buttonBackgroundThread" and "buttonBlockGUIThread" and use window key, you will see that current time is keep displaying in Output. This works when you have debugger attached. If you follow this scenario on device without attached degubber you will see that app is getting killed by OS. To prove that app is displaing last update time at start.
So my question is: how to get managed threads keep running while app is in background? I'm attaching sample project, so you can test on your device and see that managed thread get suspended when you use window key.
Is maybe some way to use native threads that won't get suspended? I see your WebServer can run while app is in background. However you used native listeners.

Related

a better DestroyWindow?

I need a tiny, tiny app that just closes the current foreground window.
I ended up writing a small app that just sends the OK virtual key which works fine except that it seems HTC X Button doesn't capture the VK so the default action is executed (SmartMinimize) instead of the action I have HTC X Button set up to perform (real close).
My second solution was to write a small app to send the WM_Close message which worked fine. I later changed it to the destroy message for two reasons ... 1) terminate without any prompting and 2) because there is already a DestroyWindow function so I don't need to sendmessage:
Code:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
HWND hwnd = GetForegroundWindow();
DestroyWindow(hwnd);
return 0;
}
What I'd like to do is make it a bit more intelligent and, rather than Destroy blindly, prevent it from closing shell32 or cprog, yet properly close what I can only presume are it's children (such as the Programs or Settings Window).
I'm new to windows mobile native coding so I'm having some trouble debugging and developing.
bump ... no developers?
If not, is anyone aware of a small application that merely closes the topmost window (actual close, not smart minimize)?
Would you like me to move your thread to the Dev&Hack section?
I guess but I'm a bit confused ... Last time I asked a dev question in Development and Hacking I got chastised for not posting in Q&A.
If it's cool with you then sure!

Combobox with Smartphones vs. WinMo

With the help of the peeps here, i got my little program working on the WinMo (touch screen) platform. Now im working on converting it into the Smartphone (non-touchscreen) platform. Seems with each medium im go, its more and more restrictive :|
anyway. I have a combobox on the screen. I has a few numbered values used to generate a random number. On the windows and winmo verson, i can just select the number from the drop down combobox, and it will generate a random number based on the selected item..
However in the Smartphone version, despite having the combobox and dispite selecting a number from it, when i hit the generate button (ie the enter button) it brings up a window with all the values in the combo box, asking me to select one from it. One when i pick one and hit "Done" does it process.
How can i get it to pull from the combobox list and Not bring up the extra screen?
Also, When the program first starts, despite me defining a default index, there is no number displayed in the combobox when it first starts up. And ideas on how to fix this?
Thanks in advance.
Good fun isn't it?
When you move from PPC to Smartphone some of the .NET objects dissappear and others behave completely differently.
OK lets do these one at a time. The Enter/Action key causes the ComboBox to display its list of contents, as a new window. It is coded into the object itself. To bypass it, you have to trick it into thinking it has already been dealt with. On the KeyDown event of the ComboBox add
Code:
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == System.Windows.Forms.Keys.Enter)
{
e.Handled = true;
}
}
Voila!
The enter key is ignored and nothing happens. Add any processing code here to deal with the selected item if required, as the control itself will never see that the 'Enter' key has been pressed.
To get the box to display its value when your application starts, use :
Code:
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
}
It doesn't actually change anything as it zero to start with, but it will trigger the ComboBox to redraw itself as it thinks it has changed.
Good luck.
The "comboBox1.SelectedIndex = 0;" ive tried already, didn't seem to help. Ill try the other when i get a moment..
I should also mention ( thought i did before, sorry) that im working with VB (for school) tho converting that code to vb shouldn't be too hard
OK I'll code it up in VB and post it. But it will have to wait until I can get to a suitable machine on which to do it. Monday onwards....... Watch this space.
Here it is. VS 2005. (2008 will update it). Both problems mentioned in the original post are corrected. All the extra lines of code added by VS for the KeyDown event have been removed.

Link contact adress to Nokia Drive

I use my7rom on my Omnia 7.
Is there anyway to link a contacts adress to Nokia Drive instead of Maps (stock wp7 app). It would be much more practical if Nokia Drive opened a navigation session instead.
Anyone up for the challenge? A reg-tweak perhaps?
// Manneman
Skickat från Windows Phone 7.8
There's two parts here. The first is identifying the correct "filetype" or URI scheme that is used for navigation. That shouldn't be too hard; a little digging in HKCU should reveal it. We already know about ones like callto: and http: and I'm actually (slowly) working on an app to allow people to easily change them. The second part is finding the correct command to load that address or route in the Nokia Maps app. If the app supports pinning routes or destinations to Start, this is probably possible. If not, it may not be possible in the app. Most apps aren't designed to accept command-line parameters, so even if you make them the default handler for a given filetype or URI scheme, they ignore the value you send them and just start as though launched from Start.
GoodDayToDie said:
If the app supports pinning routes or destinations to Start, this is probably possible.
Click to expand...
Click to collapse
Nokia Drive supports pinning to start so it should be possible. Unfortunately I can't tell you exact command line parameters 'cause my Lumia 900 still "in jail"
Let me see if I have a copy of the Nokia Drive XAP handy. I'll need to decompile it to figure out the correct parameters for launching it with the intent of navigating to a specific location. Note also that this might not be possible directly - for example, the app might store a list of locations internally, and the tiles only provide an index into that list rather than providing the location directly - but that just requires another layer of indirection.
In that case, you create an app that gets registered as the navigation handler, and in response to a navigation request, it writes the requested location into the Nokia Drive app and then chain-launches Nokia Drive with the index of the newly written location. That's just an example of one way that this might go wrong, but overall, the odds are actually pretty good. Obviously, all of this will require, at a minimum, write access to the HKCR hive in the registry.
Ah, guys! You are so kind helping me out. I´m really certain alot of members in the WP7 section would love for this to work!
// Manneman
GoodDayToDie said:
I'll need to decompile it to figure out the correct parameters for launching it with the intent of navigating to a specific location
Click to expand...
Click to collapse
GoodDayToDie, you may try much simpler solution. Just create assembly (dll) to show startup parameters in message box, and replace main Nokia Drive dll (but pin some location first).
That's actually harder than it sounds; even if the app is sideloaded (which would mean I already have the DLL) my fake would have to mimic the internal structure of the real app to a degree (namespaces, class names, default actions, etc.). That's not hard, but decompiling .NET is pretty trivial too.
AFAIR, Nokia Drive is obfuscated (but I'm not 100% sure). Also, you don't need to duplicate all names and structures; just a stuff mentioned in WMAppManifest (I hope so). BTW, I forgot: I still have unlocked handset; if I'll found time, will try today later.
Update: tried but without of luck What I did:
- installed Nokia Drive first;
- downloaded map and pinned current location;
- created fake app with same app guid and namespace name ("Drive"), and performed app update (that operation completely override whole solution but NokiaDrive tile still pinned to the start screen);
- tried a few different page names (_default.xaml, QuickStartPage.xaml, DestinationPickerPage.xaml, FavoritesPage.xaml) with code
Code:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show("Hello from fake dll");
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
{
string[] keys = NavigationContext.QueryString.Keys.ToArray();
string[] values = NavigationContext.QueryString.Values.ToArray();
string param = "";
for (int i = 0; i < keys.Length; i++)
{
param += keys[i] + " -> " + values[i] + "\n";
}
MessageBox.Show("parameters: " + param);
}
}
But result always the same: app doesn't start from the pinned tile
Update 2: Finally, I did it
The trick is:
- do the same as I've described above (you should have pinned tile from ND);
- add following code to the start page:
Code:
public MainPage()
{
InitializeComponent();
var appTile = ShellTile.ActiveTiles.Last();
if (appTile != null)
{
//MessageBox.Show(appTile.NavigationUri.OriginalString);
EmailComposeTask emailTask = new EmailComposeTask();
emailTask.Subject = "NokiaDrive pinned parameters";
emailTask.Body = appTile.NavigationUri.OriginalString;
try
{
emailTask.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK);
}
}
}
- run app as usual (not from tile);
We allset - all params are sent to our email (I'm too lazy to manually copy all stuff )
Here we are (start parameters; bold values are changed for privacy reason ):
/_default?destination.name=200 SomeName Street&destination.latitude=49.5255378801376&destination.longitude=-72.4296837244183&destination.address.street=SomeName Street&destination.address.houseno=200&destination.address.district=&destination.address.county=&destination.address.city=SomeCity&destination.address.state=&destination.address.country=USA&destination.address.postcode=05720&destination.hashCode=371767793destination.address.statecode=MA&pinnedFrom=Favorites
P.S. Just found: Navigon also has ability to pin address to the start tile So, if you find the way to modify map protocol (or how it calls), it will be a really nice hack! BTW, could you remind me: do we have ability to launch assembly by GUID (on the full-/policy-unlocked phones)? If "yes", it's possible to write a real nice "proxy" app to handle map requests
I don't know about launching assemblies directly, but it's certainly possible to launch apps by GUID. It doesn't even require anything more than dev-unlock in fact (although of course you can only launch apps that you could launch anyhow). So yes, a proxy app is totally possible. That's actually what I'm working on (started as a project to make a Kindle ebook file loader, that would pur .mobi/.prc file in the Kindle app's folder and then launch the app).
GoodDayToDie, could you please, take a look to the registry, for default map protocol handler and figure out how to change that stuff? I'm pretty busy these days (and probably will be extremely busy couple of next months) but we can cooperate and create this app...
I'll investigate, but you're not the only one busy. If you've noticed a lack of software from me recently, it's due to the nex job I got some months back; I love it, but it leaves me with a lot less time for phone hacking if I want to still have a life outside of that.
With that said, this actually ties into the work I'm already doing with things like filetype handling and default browser switching. I can send you my HKCRlib, at a minimum; it's a library that simplifies interacting with HKCR, including creating backups of important values when they change, and reverting the backups.
GoodDayToDie, truly, I'm not much interested (personally) in that hack 'cause I can't use it for my Lumia 900. So it's only for the community needs but because of lack of time, I believe, we may put it on hold.

[DEV][LIBRARY][2.0.2] Android Async TaskManager

Android Async TaskManager
AsyncTask is a great tool, allowing one to run background tasks while interacting with the UI before, while and after. However it does come with a few issues, mostly related to the way Android act when a user flips the screen or in other ways creates a detachment of the UI. AsyncTask is not equipped to handle these circumstances.
TaskManager is an extension of AsyncTask which fixes it's issues (Based on an idea of Santiago Lezica) and on top of that, provides additional features.
Source & Documentation
https://github.com/SpazeDog/taskmanager
Features
Makes sure that UI inteaction waits until the UI is pressent
Makes sure that flipping the screen does not produce multiple instances running the same tasks
Adds a new inteaction to AsyncTask onUIReady() and onUIPause() which is invoked whenever the UI is detached and re-attached
Compatible with both native fragments and the support library
Helper methods that makes it easy to use it in both Activities and Fragments
Deviates
Like mentioned above, this is based on the idea of Santiago Lezica whom made a pretty decent example. There was however a few things that bothered me, which made me decide to build my own from scratch.
The tasks should only be handled by the Task class and not be divided between the Task and the Manager. The Managers job should only be to keep track of the UI status and then report to the Tasks whenever this changes. It is then up to the Task what action should be taken depending on the current state.
I was missing the onUIReady() and onUIPause() methods which helps deal with attachment and detachment of the UI from within each individual task. Usefull to handle things like Progress Dialogs.
Using onActivityCreated() and onDetach() in the Manager does not work properly. They execute upon screen flip, but not on application pause and resume, which is also an attachment and detachment of the UI.
It is fine to include the AsyncTask onProgressUpdate() method, but without including publishProgress(), you can't really use it for anything.
The onPreExecute() method should be managed via the pending method like the rest of the methods, otherwise you will end up with a lot of application crashes.
If one should decide to built an application for newer Android versions only, there is no reason to use the support library, so there should be support for both.
I also wanted something that could return the current object. getActivity() is fine when working in an Activity, but this should also be able to run from within fragments. So a getObject() was added.
How it works
Take a look at Santiago's blog
Code:
public class MyActivity extends Activity {
private ProgressDialog mProgressDialog;
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Task<Context, Void, Boolean>(this, "nameOfMyAsyncLoader") {
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void onUIReady() {
((MyActivity) getObject()).mProgressDialog = ProgressDialog.show( (Activity) getActivityObject(), "", "Loading...");
}
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void doInBackground(Context... params) {
return someMethod( params[0] );
}
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void onPostExecute(Boolean result) {
((MyActivity) getObject()).mProgressDialog.dismiss();
if ( result ) {
...
} else {
...
}
}
}.execute( getApplicationContext() );
}
}
No mater if you execute this from within an Activity, Fragment or the same using the Support Library, you just parse this to the constructor. If you execute it from within a fragment, you need to make sure that you parsed a Tag Name when you added it with FragmentManager. TaskManager does not save instances of the object you parse, it just saves the information needed for it to find it again. With fragments, this means Tag Names. Without it, getObject() will return NULL on Fragments.
Download Pre-built Jar
2.0.2 (2013-06-28) (MD5: 88dbced8ebc4db9dea1b9cf12ab0da40)
[Default Mirror] SourceForge.net

[APP] Run android java snippets live in browser

Hi, I've made an app together with a website where you can run code like this
Code:
Toast.makeText(this, "Hello World!", Toast.LENGTH_LONG).show();
which will show a toast message in your app. Or you can read the accelerometer, files or whatever you program on the fly.
The app is just finished so it is still in a test phase. I would love to hear what you think about it.
I can't submit links yet, but if you search in the playstore for
"runondroid"
written in one word you will find the app (run on droid), the website is the same with a dot com at the end
I've been monkeying around with the app and so far it's awesome with one minor issue. How the F#@* do you make use of a class once you've defined it? I keep getting an error about expecting a class, interface, or enum.
Example:
Code:
public class Foo {
private void bar(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
}
Foo.bar("baz");
This particular example will generate the exact error, in fact. Am I just brain dead this morning or is there an unusual way to finagle this into functioning?

Categories

Resources