launch activity while ConfirmationActivity is displayed - wear-os

I have an activity that launches a confirmationActivity onclick(). I want that, while the confirmation activity is displayed, a new activity is launched so that when the confirmation activity ends, the new activity is displayed.
#Override
public void onTimerFinished(View view) {
//delayed confirmation
Intent intent = new Intent(getActivity().getBaseContext(), ConfirmationActivity.class);
intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,
ConfirmationActivity.SUCCESS_ANIMATION);
intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE,
"Run Saved!");
startActivity(intent);
Intent mainIntent = new Intent(getActivity(), WearUploadRunActivity.class);
startActivity(mainIntent);
mResults.finishIt();
end = true;
}
my code is like this atm. In this case, the confirmation activity is not displayed because the parent activity(mResults) is killed before it is displayed...
Can someone help me with this issue? I just want to activity A launch confirmationActivity and then when the confirmationactivity ends the activity B is displayed.
EDIT:
#Override
public void onTimerSelected(View v) {
if (animation == false) {
mDelayedView.start();
mDelayedView.setListener(this);
animation = true;
} else {
mDelayedView.reset();
animation = false;
}
}

You shouldn't start both activities as you are doing there. You should start your ConfirmationActivity and then, you can use the callbacks onTimerFinished() or onTimerSelected() of the ConfirmationActivity to trigger the start of the second activity.

Related

Toast Message Showing Continiously when Rapidly Click Button

Here I am showing toast message in Xamarin Forms Android
My Code:
Inside my Android Class
public void ShortAlert(string message)
{
Toast.MakeText(Forms.Context, message, ToastLength.Short).Show();
}
I am showing this toast message when user click on A Button.But When user rapidly click the button then it will shoing continiously(5 times button click showung toast 5 times).
so I want if the user click on this button second time then previous toast should be cancel.
How to do this in Xamarin form android?
You can try cancelling the Toast than it wont show on screen for a long time
public void ShowToast(string message)
{
if (objToast!= null)
{
objToast.Cancel();
}
objToast = Toast.MakeText(Forms.Context, message, ToastLength.Short);
objToast.Show();
}
Declare objToast on class level like this
private Toast objToast;
You could add the effective time of a click, for example, only the first click is valid for multiple clicks within 3 seconds,so you could change the code like this :
public static int MIN_CLICK_DELAY_TIME = 3000;//the effective time
private long lastClickTime = 0;
public void ShortAlert(string message)
{
long currentTime = Calendar.Instance.TimeInMillis;
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME)
{
lastClickTime = currentTime;
Toast.MakeText(Forms.Context, message, ToastLength.Short).Show();
}
}

nsmenufx MenuToolkit.setApplicationMenu producing inconsistent behavior

I have a JavaFX application for Mac and I'm using NSMenuFX to create the menu bar. I create my application menu using MenuToolkit. If I use the method setApplicationMenu the menu displays correctly. For example it says Quit MyApplication instead of Quit com.example.MyApplication. However, I have code that cancels the closing of the application if certain conditions are met. I have an EventHandler on the Stage that handles the on close request. If the application should not close the WindowEvent is consumed. The problem is the application still closes. However, if I do not use setApplicationMenu, the menu does not display correctly (it says Quit com.example.MyApplication) but consuming the WindowEvent does stop the closing of the application. I am using Java 1.8u77. Any ideas on what I'm doing incorrectly? I cannot reproduce this problem in the sample code that comes with NSMenuFX. Below is the code that creates the menu bar.
private void createMenu(VBox appBox) {
// Create the menubar
MenuBar menuBar = new MenuBar();
menuBar.useSystemMenuBarProperty().set(true);
MenuToolkit tk = MenuToolkit.toolkit();
String appName = "MyApplication";
Menu appMenu = new Menu(appName);
menuBar.getMenus().add(appMenu);
MenuItem aboutItem = tk.createAboutMenuItem("MyApplication");
aboutItem.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
AboutDialog aboutDialog = new AboutDialog(null);
aboutDialog.initOwner(stage);
aboutDialog.showAndWait();
}
});
appMenu.getItems().add(aboutItem);
appMenu.getItems().addAll(new SeparatorMenuItem(),
tk.createHideMenuItem(appName), tk.createHideOthersMenuItem(),
tk.createUnhideAllMenuItem(),
new SeparatorMenuItem(), tk.createQuitMenuItem(appName));
tk.setApplicationMenu(appMenu);
// Add the File menu
Menu file = new Menu("File");
menuBar.getMenus().add(file);
// Add the Print item
print = new MenuItem("Print");
print.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null && job.showPrintDialog(
lineChart.getChart().getScene().getWindow())) {
boolean success = job.printPage(lineChart.getChart());
if (success) {
job.endJob();
}
}
});
file.getItems().add(print);
// Window Menu
Menu windowMenu = new Menu("Window");
windowMenu.getItems().addAll(
tk.createMinimizeMenuItem(), tk.createZoomMenuItem(),
tk.createCycleWindowsItem(), new SeparatorMenuItem(),
tk.createBringAllToFrontItem());
menuBar.getMenus().add(windowMenu);
tk.autoAddWindowMenuItems(windowMenu);
tk.setGlobalMenuBar(menuBar);
}
NSMenuFX has been modified to correct this problem. Look for version 2.1.4 or higher.

Start specific view of Gluon App from a notification

I set up an alarm to show a corresponding Notification. The PendingIntent of the Notification is used to start the Gluon App main class. To show a View other than the homeView, I call switchView(otherView) in the postInit method. OtherView is shown, but without AppBar. While it's possible to make the AppBar appear, I wonder if this is the right approach.
#Override
public void postInit(Scene scene) {
// additional setUp logic
boolean showReadingView = (boolean) PlatformProvider.getPlatform().getLaunchIntentExtra("showReadingView", false);
if (showReadingView) {
switchView(READING_VIEW);
}
}
When triggering anything related to the JavaFX thread from another thread, we have to use Platform.runLater().
Yours is a clear case of this situation: the Android thread is calling some pending intent, and as a result, the app is started again.
This should be done:
#Override
public void postInit(Scene scene) {
// additional setUp logic
boolean showReadingView = (boolean) PlatformProvider.getPlatform().getLaunchIntentExtra("showReadingView", false);
if (showReadingView) {
Platform.runLater(() -> switchView(READING_VIEW));
}
}

Return from background relaunches the entire app

I have a xamarin forms app, and I want to avoid a scenario where the startup flow has ended, all the data was loaded and displayed, and when the app goes to background and return, the same screen before going to background will be displayed instead of going all over the startup process again.
As far as I see, each time the app returns from background, MainActivity calls method OnCreate, which initiates all the startup process.
There were some bugs in Xamarin.Forms (I don't know if they were fixed). Dirty hack is:
public class MainActivity : FormsApplicationActivity
{
public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
{
if (this.ActionBar.Title == "YourMainMenuTitle")
{
if (keyCode == Keycode.Back && e.RepeatCount == 0)
{
MoveTaskToBack(true);
return true;
}
}
return base.OnKeyDown(keyCode, e);
}
// ...
}
More here: http://forums.xamarin.com/discussion/comment/89844

How to dismiss a Alert Dialog in Mono for android correctly?

In my application i have a Custom AlertView, which works quite good so far. I can open it the first time, do, what i want to do, and then close it. If i want to open it again, i'll get
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first
so, here some code:
public Class ReadingTab
{
...
private AlertDialog AD;
...
protected override void OnCreate(Bundle bundle)
{
btnAdd.Click += delegate
{
if (IsNewTask)
{
...
AlertDialog.Builer adb = new AlertDialog.Builer(this);
...
View view = LayoutInflater.Inflate(Resource.Layout.AlertDView15ET15TVvert, null);
adb.setView(view)
}
AD = adb.show();
}
}
}
that would be the rough look of my code.
Inside of btnAdd are two more buttons, and within one of them (btnSafe) i do AD.Dismiss() to close the Alert dialoge, adb.dispose() hasn't done anything.
the first time works fine, but when i call it the secon time, the debugger holds at AD = adb.show(); with the Exception mentioned above.
So what do i have to do, to remove the Dialoge from the parent? i can't find removeView() anywhere.
If you are setting up an AlertView once and then using it in multiple places (especially if you are using the same AlertView across different Activities) then you should consider creating a static AlertDialog class that you can then call from all over the place, passing in the current context as a parameter each time you want to show it. Then when a button is clicked you can simply dismiss the dialog and set the instance to null. Here is a basic example:
internal static class CustomAlertDialog
{
private static AlertDialog _instance;
private const string CANCEL = #"Cancel";
private const string OK = #"OK";
private static EventHandler _handler;
// Static method that creates your dialog instance with the given title, message, and context
public static void Show(string title,
string message,
Context context)
{
if (_instance != null)
{
throw new Exception(#"Cannot have more than one confirmation dialog at once.");
}
var builder = new AlertDialog.Builder(context);
builder.SetTitle(title);
builder.SetMessage(message);
// Set buttons and handle clicks
builder.SetPositiveButton(OK, delegate { /* some action here */ });
builder.SetNegativeButton(CANCEL, delegate { /* some action here */});
// Create a dialog from the builder and show it
_instance = builder.Create();
_instance.SetCancelable(false);
_instance.Show();
}
}
And from your Activity you would call your CustomAlertDialog like this:
CustomAlertDialog.Show(#"This is my title", #"This is my message", this);

Resources