I want to know how to switch between two Midlets i.e. Go from First Midlet to Second Midlet on pressing command?
MIDP 1.0 specified only one way to start a MIDlet: manual activation by the user.The MIDP 2.0 specification adds two new mechanisms to launch a MIDlet: in response to an incoming connection or at a scheduled time. The new javax.microedition.io.PushRegistry class handles both.
You can use Alarms to Launch MIDlets.The PushRegistry.registerAlarm() method Registers a timer-based alarm to launch the Midlet.It supports one outstanding wake up time per MIDlet in the current suite.(So target midlet must be registered in the JAD or manifest file)
In the MIDlet source code include:
...
import javax.microedtion.io.PushRegistry;
and in your commandAction method:
...
String MIDletname = "yourMIDletName";
Date date = new Date();
long currentTime = date.getTime();
long nextTime = currentTime + 2000;
PushRegistry.registerAlarm( MIDletname, nextTime );
...
References:
How can a MIDlet be launched automatically?
The MIDP 2.0 Push Registry
Related
I know, there is always a lot of questions about this error BUT I didn't succeed to fix it with the previous answers...
So, please, let me explain.
I'm working with the Hololens tech. Recently, I have updated from HoloToolKit to MRTK V2 (new SDK provided by Microsoft and the community). My app worked with HoloToolKit, Unity and 2017.4. I updated for MRTKv2 and 2019.2 (recommended).
I have some scripts that use the camera position. In my previous app, Camera was BiCamera (GameObject), child of Basic (GameObject). And my BiCamera was tagged as MainCamera. Right now, my camera was Main Camera (with a space between the 2 words), tagged MainCamera, child of MixedRealityPlayspace. This camera is provided by the MRTKv2. I can't change the settings.
So, when I'm in a Play mode I have this message in yellow :
The referenced script on this Behaviour (Game Object 'Main Camera') is missing!
And when I move my Main Camera in order to simulate a walk of the user (Hololens = augmented reality), I have this message in red :
NullReferenceException: Object reference not set to an instance of an object
TextSpeedUI.Update () (at Assets/Scripts/TextSpeedUI.cs:23)
I think the second message is linked to the first... My script TextSpeedUI needs the camera.transform to calculate walking speed (in fact not directly, he finds the public variable from another GameObject, but this GameObject requires Camera.transform).
An other option is linked with the GameObject Main Camera provided by MRTK because when I select this GameObject I have a missing script. A message says that I have to fix compile errors... But perhaps it's a consequence not the origin... I'm lost.
TextSpeedUI.cs 23
if (sd.isActiveAndEnabled && sd.Steps.Count > 4)
{
xzSpeed = (sd.Steps[sd.Steps.Count - 1].localMinPosition - sd.Steps[sd.Steps.Count - 4].localMinPosition) / ((sd.Steps[sd.Steps.Count - 1].t - sd.Steps[sd.Steps.Count - 4].t));
txt.text = (xzSpeed.magnitude * 3.6).ToString("0.##"); // speed in km/h
}
sd comes from public StepDetector sd; which is at the beginning of my script TextSpeedUI.cs
And my script StepDetector.cs calls public DataManager dm;
In my DataManager.cs script, I call at the beginning :
public Camera Cam { get; private set; }
And in void Start :
Cam = Camera.main;
Thanks a lot
I've solved by myself (just remove the component). It seems that it doesn't have consequence on my scene...
How should I await a Task in DidFinishedLaunchingWithOptions which has no Task returning signature?
bool FinishedLaunching (UIApplication app, NSDictionary options)
I have to await an initialization Task of a DataManager from my PCL in the plattform specific project. In the Android specific project I can add the async modifier to the main method which returns void. But the iOS main method returns bool.
You shouldn't await any initialization in this method since this one has a limited time to respond back, which if I am not wrong it's 24 seconds. After that time your application will be killed by the system.
I do suggestion instead to add a "splashscreen" as your first ViewController, if you need this to be done in the Platform specific project. There you can make any initialization and even add some nice animation to let the user know. Or you can have this initialization Page in the Xamarin.Forms project and transition from there to your current MainPage once the initialization is completed.
#apineda is totally right that you shouldn't be doing this. However, if you HAVE to...
You can call .GetAwaiter() and .GetResult() on your Task.
Example:
...
public Task<string> GetSomeStringAsync();
...
var myString = GetSomeStringAsync().GetAwaiter().GetResult();
...
Then you'll get the data you need. Be careful not to break your 17 second timeout!
I'm facing a problem after the migration from Spring 2.5, Flex 3.5, BlazeDS 3 and Java 6 to Spring 3.1, Flex 4.5, BlazeDS 4 and Java 7. I've declared a ClientFeed in order to send a sort of "alarm" messages to the flex client. There are three methods those alarms are sent. The first one is via snmp traps, a thread is started and wait for any trap, as one is received an alarm will be sent. The second method is via a polling mechanism, at the beginning of the web application a thread is started and will poll after a constant amount of time the alarms and send them to the client. The third method is the explicit poll command from the user, this will call a specific function on the dedicated service. This function uses then the same algorithm used in the second methods to perform a poll and shall send those alarms to the client.
The problem is that after the migration the first two methods are working without a problem, but the third one doesn't. I suspect there is a relation with the threads. Is there any known issue between messagetemplate and the threads with the new frameworks ?
Here is a snapshot of the used client feed:
#Component
public class ClientFeed {
private MessageTemplate messageTemplate;
#Autowired
public void setTemplate(MessageTemplate messageTemplate) {
this.messageTemplate = messageTemplate;
}
public void sendAlarmUpdate(final Alarm myAlarm) {
if (messageTemplate != null) {
System.out.println("Debug Thread: " + Thread.currentThread().getName());
messageTemplate.send(new AsyncMessageCreator() {
public AsyncMessage createMessage() {
AsyncMessage msg = messageTemplate.createMessageForDestination("flexClientFeed");
msg.setHeader("DSSubtopic", "Alarm");
msg.setBody(myAlarm);
return msg;
}
});
}
}
}
By the three methods I reach this piece of code and the displayed thread name are respectively: "Thread-14", "Thread-24" and "http-bio-80-exec-10".
I solved the problem by creating a local thread on the server to perform the job. Therewith the client feed is called via this new created thread instead of the http-thread.
i have added following coe in my view class but still it's not working.
BOOL CtestView::PreCreateWindow(CREATESTRUCT& cs)
{
if (CView::PreCreateWindow(cs))
{
WNDCLASS wc;
// Get the class information for the default MFC view class.
::GetClassInfo(AfxGetInstanceHandle(),cs.lpszClass,&wc);
// Register a new class using the attributes of the default
// view class, and make it the new default class.
cs.lpszClass = AfxRegisterWndClass(wc.style | CS_DBLCLKS,
wc.hCursor,wc.hbrBackground,wc.hIcon);
return TRUE;
}
return FALSE;
}
Is your window set to receive double click events? See this MSDN article. Quote:
An application-defined window does
not, by default, receive double-click
messages. Because of the system
overhead involved in generating
double-click messages, these messages
are generated only for windows
belonging to classes that have the
CS_DBLCLKS class style. Your
application must set this style when
registering the window class.
You can also create your own double-clicks by managing up/down events, the delta between the cursor locations of those events and the time between them.
So for example, this sequence:
Down message (save control)
start timer
less than 250 milliseconds passed
up message (on same control)
less than 250 milliseconds
Down message (on same control)
less than 250 milliseconds
up message (on same control)
= double click
If in that sequence your timeout expires or the control changes you reset your counters and variables since the action was not a double click.
I have a midlet which has got a static variable. I need to keep the record of all the instances created in this variable. but it does not work like static variable. my code segments look like this. I am running this midlet on sun wireless toolkit 2.5.5. I can create many objects of same midlet from that toolkit but still my counter shows only 1.
public class SMS extends MIDlet implements CommandListener {
private Display display;
private TextField userID, password ;
public static int counter ;
public SMS() {
userID = new TextField("LoginID:", "", 10, TextField.ANY);
password = new TextField("Password:", "", 10, TextField.PASSWORD);
counter++;
}
public void startApp() {
display = Display.getDisplay(this);
loginForm.append(userID);
loginForm.append(password);
loginForm.addCommand(cancel);
loginForm.addCommand(login);
loginForm.setCommandListener(this);
display.setCurrent(loginForm);
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
System.out.println("Total Instances"+counter);
everytime, counter shows only 1 object created.
The only system I've seen that allows static variables to remain between 'invocations' of an application is Android. I've never once seen a J2ME device that maintains static data between invocations of a MIDlet. However, MIDlets within a MIDlet suite can share static data, as described here, while at least one of them is running.
If you want to maintain data between invocations of a MIDlet, you need to use the Record Store APIs in javax.microedition.rms, which provide access to a persistent store.
Your MIDlet is only instantiated once. Kind of.
The MIDP runtime will probably not allow you to launch the same MIDlet twice as long as it is already running.
If you exit the MIDlet, counter goes back to 0 because it is still a in-RAM value and the Java Virtual Machine process is terminated.
On some Nokia series40 phones, the JVM process is never terminated so you could use this to show how many times the MIDlet was created since the last time the phone was switched on.
Static variables are stored in a Class object in the JVM memory. You need to understand class loading (and the usual lack of support for class unloading in J2ME) to figure out what you can store in static variable.
I would suggest moving counter++; to startApp() as it could be called everytime the MIDlet is brought to the foreground.
That would also allow you to store counter in an RMS record for additional accuracy.