Android Dialog dismiss using handler - android-dialog

I meet a stranger question,when I read the android GlobalAction source code,I find that it will start a dialog,but it add a judgement which will judge whether this dialog has been shown,if it was shown before,it will be dismissed and then show it.The stranger things is that it dismiss the dialog,than use Handler to send a message to create and show dialog again,I can't understand why it needs to send a handler message,I think it just calls dialog dismiss function.then calls show function,it no problem.The comment said:"Show delayed, so that the dismiss of the previous dialog completes",but I also can't understand the meaning,please someone help me explain it,Thanks a lot.
if (mDialog != null) {
mDialog.dismiss();
mDialog = null;
// Show delayed, so that the dismiss of the previous dialog completes
mHandler.sendEmptyMessage(MESSAGE_SHOW);
}

Many Android UI functions are themselves implemented using messages, and so do not complete immediately. When you call Dialog.dismiss(), Android queues a message that does the actual dismissing. The author of this code wants to ensure the dialog is actually dismissed before showing it again, and so she posts her own message, which will not run until after the one posted by Android.

Related

Simulate a click on start button (at bots)

Is it possible to simulate a click on the start button without saying /start ?
This button simply sends a message with "/start" as the text to the bot, which can be done with client.send_message:
client.send_message(bot, '/start')
If it has parameters add them after a space:
client.send_message(bot, '/start argument')
Raw API also has messages.startBot which offers some more flexibility and I believe hides the start message.

onGoing notification can still be removed by user, manually

i create an application and i want after click on specific button, a "Permanent Nofitication" show on notification bar.
i search for it and use these codes:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_clip_board_service)
.setContentTitle(getResources().getString(R.string.notifTitle))
.setContentText(getResources().getString(R.string.notifText))
.setOngoing(true);
the ongoing method, prevent user to manually clear the notification.in my emulator(genymotion), everything is ok.but in my real Phone(Huawei G8) when i try to remove notificaiton, a pop-up menu appeared and say:
Not Recomended
removing ongoing notification may affect app stability.
the menu has already two buttons:cancel and Remove.and i can remove the notification.:(
i don't want user manually remove notification.
is the problem about my Phone or setOngoing(true) method?
thanks in advance...
Based off what I'm seeing for my app that behaves similarly, it appear Huawei phone's always allow clearing notifications and shutting down the app. My app even runs as a device administrator and it can still be cleared.

How to display the custom message in SDL Tridion Message bar?

I want to display my custom message (Say for Ex: some message needs to display when Page is save event is triggered) in SDL Tridion CME Message bar. How to do this?
From an event system you can only display ERROR messages.
If your Event code throws an error the "Message" will be displayed in the Message bar.
For other type of messages you need to use Javascript/CM Extensions. You can find an example of an event system that shows a message here.
Nuno covered your options pretty well.
If you want to show a message from your JavaScript code, this is usually my starting point:
$messages.registerNotification("Hello world");
If you put this in your JavaScript code (or just paste it into a JavaScript console), it will show a blue bar with "Hello World" in it.
There are many types of messages, each of which shows up slightly differently. What I usually do if I need more than a notification is:
type $messages. in a JavaScript console in a browser where the web GUI is loaded
go through the list of relevant methods to see what looks most promising (they all start with register)
perform a text search on the source code for the method that I am looking for
This leads me to an example of how that method is used in the GUI already and is a great starting point for my own code.
Update
Alexander Klock recently wrote a thorough explanation of the message types available on his blog.

Wrapping AVCam demo from WWDC 2010

I have three camera-based apps (that take still pictures) in the app-store and have got feedback that the UIImagePickerController interface is very slow - and I can't deny that. So, to improve the performance of the app, I started to experiment with the AVCam Demo source code from the WWDC 2010.
Since the AVFoundation framework does not interact with the UI Kit, I have been successful at wrapping a view around the demo. I am able to transition between the view controllers successfully. The only thing that I've modified is replaced the Record button with the Exit button (to exit to the wrapping view controller)
The modified app works fine during the first session (wrapper -> demo) If I exit the demo to the wrapper, and come back to the demo second time , the video frame in the preview layer freezes a second or two after. The app itself does not freeze - just the video is frozen. At this point, all UI buttons are active. But, when I tap "Still" button to capture the image, I get the following error in an alert:
The operation cannot be completed (AVFoundationErrorDomain error - 11800.)
This cannot be duplicated in the original demo code - because you can't close and reopen the session. So, I am wondering if it has anything to do with the way I "exit" from the session in my test. Here's the "exit" action that I added in the demo code:
- (IBAction)exit:(id)sender
{
[[self captureManager] stopRecording];
[self dismissModalViewControllerAnimated:YES];
}
Is this sufficient - or did I miss something?
Regards, Sam.
There's a little problem of cleaning up a capture session in an orderly fashion, as there's some asynchroneous calls with no alerts of when they're done.
Try stopping and releasing as suggested in this question:
How to properly release an AVCaptureSession
(take the solution with most up votes)
If that doesn't help you may need to post some more code here. Are you sure that's all you changed?
Good luck!
Oded.

How to add Mate Listeners using Action Script

in one of my forms, I have used the following code for adding Mate Listeners
<mate:Listener type="{DBEvent.Update_Result}" receive="{onUpdateResults(event)}"/>
I am displaying this form as a popup. What happening is, for the first time, onUpdateResults method executed only once as expected. Then i close the popup and reopened it. This time onUpdateResults method called twice, then next 4time and so on...
After so much of googling, i found that Mate Listeners are still active, even though we remove/close the popup. I tried weak references, close the popup using PopupManager.RemovePopup and so on. Nothing worked.
Then i thought of registering and unregistering the mate listeners manually using action script. So, i have tried the following code
var _listener:Listener= new Listener();
_listener.addEventListener(DBEvent.Update_Result,onUpdateResults);
to unregister...
_listener.removeEventListener(DBEvent.Update_Result,onUpdateResults);
But this is also not working.
Please somebody help me fix this issue.
Try this.
Create runtime popup windows in main application:
PopUpManager.createPopUp(this, MyPopUp, true);
MyPopUp - mx:TitleWindow from MyPopUp.mxml
Add any listeners in OnInit in MyPopUp.mxml:
_listener.addEventListener(DBEvent.Update_Result, onUpdateResults);
Close popup when you click any button (button's click event or any):
PopUpManager.removePopUp(this);

Resources