Can't Unlock Windows IOT Process after Debug - windows-10-iot-core

Trying to debug a Universal Windows app (MyTest) for Windows IOT using Local Machine. It starts the app but only displays the X screen, not my MainPage.xaml. OK, probably some bug I made. But I can't debug it and I can't unlock it. I try to put a breakpoint at App() constructor or OnLaunched and it never hits. If I Stop Debugging the X window stays up. Worse, if I kill the X window, using the window close (button in the top right), the app looks like it stops but the MyTest.exe remains locked, forever stopping me from trying to delete the exe, rebuild project, etc.
There is no MyTest app in the TaskManager (processes or details).
If I terminate ApplicationFrameHost process, the X screen will go away, but the MyTest.exe file remains locked as though the exe is still in use.
I've tried FileAssassin and it can't remove the lock.
The only thing that unlocks MyTest.exe is rebooting the machine...kind of a pain if you only get 1 debug run before rebooting the machine each time!

if you are using tasks you must terminate all.
example
BackgroundTaskDeferral _defferal;
public void Run(IBackgroundTaskInstance taskInstance)
{
_defferal = taskInstance.GetDeferral();
taskInstance.Canceled += TaskInstance_Canceled;
}
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
//a few reasons that you may be interested in.
switch (reason)
{
case BackgroundTaskCancellationReason.Abort:
//app unregistered background task (amoung other reasons).
break;
case BackgroundTaskCancellationReason.Terminating:
//system shutdown
break;
case BackgroundTaskCancellationReason.ConditionLoss:
break;
case BackgroundTaskCancellationReason.SystemPolicy:
break;
}
_defferal.Complete();
}
source: Windows 10 IOT Lifecycle (or: how to property terminate a background application)

Related

WCSession sendMessage not working

I'm calling this code in my Watch extension (and it does run, checked with a breakpoint):
[[WCSession defaultSession] sendMessage:#{
#"load": #"main"
} replyHandler:^(NSDictionary<NSString *,id> * _Nonnull replyMessage) {
...
}
} errorHandler:^(NSError * _Nonnull error) {
...
}];
In my parent app, I've got:
if([WCSession isSupported]){
NSLog(#"Apple Watch detected, activated watch deletage.");
[WCSession defaultSession].delegate = self;
[[WCSession defaultSession] activateSession];
}
The above code runs when the app is launched, and I've implemented:
-(void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *,id> *)message replyHandler:(void (^)(NSDictionary<NSString *,id> * _Nonnull))replyHandler{
...
}
But it is never called. I've once got it to work, but now, I can't debug my Watch app and iOS app together properly (they don't launch, timeout etc), I deploy them one after other. When I'm debugging Watch extension, I can see the sendMessage... method is called (and after a few minutes, my error handler is called with a timeout error), so no issue there. When I launch my main app, I also see that WCSession related code is being hit. However, when I launch my Watch app to communicate with it, didReceivedMessage... is never called.
I've deleted my app from both iPhone and Watch, restarted both devices, and restarted my Mac and tried again, but no avail. What am I doing wrong?
Even though Watch is not really reliable, it was a simple memory allocation issue in my case. I wasn't holding a strong reference to my WCSession's delegate, and it was getting deallocated before the method was called. I've created a strong reference and the problem went away.

Windows Phone 8, minimize app

Have a broblem with minimize application, when back button pressed:
protected override void OnBackKeyPress(CancelEventArgs e)
{
}
I need do not close application, just minimize him to background, have any idea for this?
You should close on back - otherwise you will fail certification for the store. If you need a background task running, instead use a Background Agent
More precise:
You can activate fast resume in the manifest:
http://msdn.microsoft.com/en-us/library/windows/apps/jj735579(v=vs.105).aspx
This will keep the instance of your app in the memory until the system cleans up the oldest apps to free memory when needed.
This is the recommended behavior and the default for all 8.1 Runtime Apps.
Hint:
Once put to the background, you app will still be suspended and no longer active.
It will be resumed once it gets back to the foreground.

How to avoid the screen to lock while the Windows Phone is plugged in

Easy as that, in android there's a setting called Stay awake that will prevent your phone to lock down while you're using it for debugging an app.
I'm looking for the same thing (could be better) for Windows Phone 8.1.
Every time I hit F5 I need to unlock my phone or I would get the following error:
DEP6600 : Deployment failed. Cannot deploy app when device screen is locked. Please make sure that the device screen is not locked, and try again.
or
Error: Application launch failed. Ensure that the device screen is unlocked and device is developer unlocked. For details on developer unlock, visit http://go.microsoft.com/fwlink/?LinkId=195284
if I run the AppDeployCmd tool myself.
Is there a way I can avoid that? (without changing my lock screen time out every time of course)
I don't think you can do this without writing a separate app. On the phone there is an option: Settings > Lock Screen > Screen time out, which you can set to maximum available. For same phones, like lower end Nokias there is an option to set that time to never, however for newer phones such as Nokia 1320 or Nokia 1520 that maximum is only 5 minutes.
I think it isn't possible, but here is an alternative
EDIT: You can write an separate app, wich you should run while you're developing other apps. This app must consist of this lines code.
DisplayRequest AppDisplayRequest = new DisplayRequest();
public MainPage()
{
AppDisplayRequest.RequestActive();
}
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
AppDisplayRequest.RequestRelease();
e.Handled = true;
Windows.Phone.UI.Input.HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
Application.Current.Exit();
}
The resolution for the error DEP6600 should be there in the code itself instead of writing a separate app. how can this be done. in other words, the moment my app is compiled build and after deployment the error shouldn't come and the app should run even when the phone is locked

Libgdx AndroidApplication native(?) crash

I have a strange problem. I use a nightly from last week. If I recall correctly it's from 23/3.
What happens is that I run a Libgdx Activity and it runs fine. Than I finish the app. I start the libgdx activity again and it crashes... This happens a lot but not all the time.
In debug mode it doesn't happen at all. Any ideas? It doesn't print any crash log but I think it has something to do with this log: http://pastebin.com/3BFrjbES
My code doesn't do any thing special right now. It's just printing the FPS in a stage....
I think there is an error in the log that may be connected: EGL error: EGL_BAD_CONTEXT.
This is printed just before the previous log.
Thanks.
What does "finish the app" mean? A pause (pressing home) or a destroy?
I wonder if it is any way related to LibGDX attempting to preserve the EGL Context. The default for Android is to not preserve it but LibGDX attempts to enable it if you are on SDK >= 11. You could try to disable preservation in your AndroidApplication subclass by doing something like:
View view = ((AndroidGraphics)Gdx.graphics).getView();
try {
Method method = null;
for (Method m : view.getClass().getMethods()) {
if (m.getName().equals("setPreserveEGLContextOnPause")) {
method = m;
break;
}
}
if (method != null) {
method.invoke((GLSurfaceView20)view, false);
}
} catch (Exception e) {
}
I found out the problem. The problem disappeared after I removed hardwareAccelaration="true" from my application tag in the manifest. I don't know why it matters as my device is 4.0.4 which means that it's enabled by default.

wakeLock does not wait for network connectivity

I am using a wakelock for a alarm to update the app state regularly. The wifi takes a while to connect on Samsung phones. Also the "keep awake" option on Wifi does not work on Samsung phones (nor are they interested in fixing the issue). So when the wakelock does happen, it should wait for wifi to connect. Do I need to create a listener for the wifi connectivity for this to work, or should wakelock, kinda block for that wifi to connect ?
mWakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "Taxeeta");
mWakeLock.acquire();
// do some network activity, in a asynctask
// in the doPost of asyscTask, release lock
Edit :
The question is, that in the AsyncTask if the network is not connected, OR takes time to get on (3g takes a while to get on), the webservice call in the Async doInBackground will fail. And I will have to release the lock anyways.
SO
Should I put in wifi/data connection listeners in ? Or is there a better way ?
I have a similar scenario - I am woken up by an alarm, the alarm's BroadcastReceiver launches a WakefulIntentService and the service starts a scan for networks. I use a stupid way of holding on to the lock1 - I intend to replace this with a latch. I suggest you replace the "AsyncTask" with a WakefulIntentService. Chances are the AsyncTask is not ever fired. In the WakefulIntentService you must acquire and hold on to a wifi lock - I would make this a static field of the YourWakefulIntentService - not entirely clear on this - it's a while back. If this does not work I would use a latch in the YourWakefulIntentService :
// register an alarm
Intent i = new Intent(context, YourReceiver.class);
PendingIntent alarmPendingIntent= PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_UPDATE_CURRENT);
public class YourReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
WakefulIntentService.sendWakefulWork(context, YourWIS.class);
}
}
//pseudocode !
public class YourWIS extends WakefulIntentService { // you must add a cstor !
#Override
doWakefulWork() {
acquireWifiLock();
enableScanReceiver();
startScan();
serviceLatch.wait();
releaseWifiLock();
}
}
// in YourScanReceiver
onReceive() {
if(action.equals(SCAN_RESULTS) {
// do something that does not take time or start another/the same
// WakefulIntentService
serviceLatch.notify();
}
}
Try first the WakefulIntentService (I guess you launch the AsyncTask from the alarm receiver). The scan receiver is a receiver registered to receive the scan results (see WifiManager docs - prefer Receivers to listeners for sleep issues)
1 : this is a working class - I just use a second wakeful intent service to keep the wake locks - have still to refactor it to use latches but this approach at least works (I have the second service (the Gatekeeper) wait on a monitor and have the wake lock inside the Gatekeeper. The gatekeeper also holds its CPU lock so all is fine (and ugly)