| Reply | « Previous Thread | Next Thread » |
|
Hi there,
I created an application with 2 midlets, MIDlet_1 and MIDlet_2 in a midlet suite. MIDlet_1 triggers MIDlet_2(which plays some music) at a certain time set in MIDlet_1. I installed my application in a Phone. However, when I open the application, and when I choose MIDlet_1, 1st it goes out of the application for a few secs and then only enters MIDlet_1. Would anyone kindly tell me why that happens and why can't it go directly to MIDlet_1? If I create I MIDlet and a simple class and not a midlet for MIDlet 2, I have no such problem. But in that case I cannot automate MIDlet_2. Is it because the vendor of my application is unknown? Any solutions to this problem. Any kind of response is welcome. |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
Hi Biz,
Where are you actually calling the midlet-2,inside the midlet-1? Please explain the same much more details.Are the both midlet in same midlet suite? Thanks R a j - The K e r n e l |
|
Join Date: Jul 2008
Posts: 329
Location: Faridabad(Delhi NCR)
ansh.chauhan
Offline
Regular Contributor
|
|
|
Quote:
Anshu Chauhan J2me Developer |
| ansh.chauhan |
| View Public Profile |
| Find all posts by ansh.chauhan |
|
Quote:
|
| sharvan1981 |
| View Public Profile |
| Find all posts by sharvan1981 |
|
How does this happen?
You are not allowed to do this: Code:
MIDlet mid2 = new MIDlet_2(); mid2.startApp(); If you are trying to use registerAlarm(), remember that your device might not be able to run two MIDlets at the same time, so running MIDlet_1 will prevent MIDlet_2 from starting. Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
Quote:
1. with the help of Push registry , or 2. by making an object of another midlet ie midlet2. Please mention ur problem in detail.. or post ur code for both midlet1 and midlet2. thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
|
Hello Everyone,
Thank you for your kind responses and sorry for not being able to explain my problem well. I will try to do it again. I am trying to use registerAlarm() method in push registry API to triger Alarm MIDlet through Pust MIDlet where I set the time for the Alarm. Alarm MIDlet uses class SoundPlayer to play and stop the music. Push MIDlet Code:
import java.util.Date;
import javax.microedition.io.PushRegistry;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* Push MIDlet automates the Alarm MIDlet
*/
public class Push extends MIDlet implements ItemStateListener,CommandListener {
private Display display; // Reference to display object
private Form form; // The main form
private Command cmAlarm; // Start the timer
private Command cmReset; // Reset to current date/time
private DateField dfAlarmTime; // How long to sleep
private Date currentTime; // Current time...changes when pressing reset
private boolean dateOK = false; // Was the user input valid?
public Push() {
System.out.println( "Push: constructor" );
display = Display.getDisplay(this);
// The main form
form = new Form("Set Alarm");
// Save today's date
currentTime = new Date();
// DateField with todays date as a default
dfAlarmTime = new DateField("", DateField.DATE_TIME);
dfAlarmTime.setDate(currentTime);
// All the commands/buttons
cmAlarm = new Command("Save", Command.SCREEN, 1);
cmReset = new Command("Reset", Command.SCREEN, 1);
// Add to form and listen for events
form.append("Set Date and Time\n");
form.append(dfAlarmTime);
form.addCommand(cmAlarm);
form.addCommand(cmReset);
form.setCommandListener(this);
form.setItemStateListener(this);
display.setCurrent(form);
}
public void startApp() throws MIDletStateChangeException{
System.out.println( "Push: startApp" );
System.out.println( "Push: startApp: return" );
}
public void pauseApp() {
System.out.println( "Push: pauseApp" );
}
public void destroyApp( boolean unconditional ) {
}
public void itemStateChanged(Item item) {
if (item == dfAlarmTime) {
if (dfAlarmTime.getDate().getTime() < currentTime.getTime())
dateOK = false;
else
dateOK = true;
}
}
public void commandAction(Command c, Displayable s) {
if (c == cmAlarm) {
if (dateOK == false) {
Alert al = new Alert("Unable to set alarm","Please choose another date and time.", null, null);
al.setTimeout(Alert.FOREVER);
al.setType(AlertType.ERROR);
display.setCurrent(al);
} else {
long amount = dfAlarmTime.getDate().getTime() - currentTime.getTime()-10000;
System.out.println( "aaa"+amount+"\n" );
scheduleMIDlet(amount);
System.out.println( "Push: destroyApp" );
destroyApp(false);
notifyDestroyed();
}
} else if (c == cmReset) {
// Reset to the current date/time
dfAlarmTime.setDate(currentTime = new Date());
}
}
private void scheduleMIDlet (long delt)
{
System.out.println( "Inside Scheduler\n" );
System.out.println( "aaa"+delt+"\n" );
try {
Date now = new Date();
PushRegistry.registerAlarm("Alarm", now.getTime() + delt);
} catch ( java.lang.ClassNotFoundException cnf ) {
System.out.println( "Push: Class not Found" );
} catch ( javax.microedition.io.ConnectionNotFoundException connnf ) {
System.out.println( "Push: Connection Not Found" );
}
}
}
Code:
import java.util.Date;
import javax.microedition.midlet.*;
import javax.microedition.io.PushRegistry;
import javax.microedition.lcdui.*;
public class Alarm extends MIDlet implements CommandListener{
private Display display; // Reference to display object
private Form form; // The main form
private Ticker t;
private Image image;
private ImageItem img;
private Command cmExit; // Exit Appli
private Command cmStop; // Stop Alarm
private SoundPlayer soundPlayer = new SoundPlayer();
public Alarm(){
display = Display.getDisplay(this);
form = new Form("");
t = new Ticker ("★ Rise and Shine ★");
form.setTicker (t);
image = null;
try { image = Image.createImage("/bell.png");
}catch (Exception e){
}
img = new ImageItem("",image ,Item.LAYOUT_2|Item.LAYOUT_CENTER|Item.LAYOUT_VCENTER,"",Item.PLAIN );
form.append(img);
cmExit = new Command("Exit", Command.EXIT, 1);
cmStop = new Command("Stop", Command.SCREEN, 1);
form.addCommand(cmExit);
form.addCommand(cmStop);
form.setCommandListener(this);
display.setCurrent(form);
soundPlayer.playsound("Play");
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
public void commandAction(Command c, Displayable arg1) {
// TODO Auto-generated method stub
if (c == cmExit) {
try {
soundPlayer.playsound("Stop");
destroyApp(false);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
} else if (c == cmStop){
soundPlayer.playsound("Stop");
}
}
}
Code:
import java.io.InputStream;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
/*This is a class that plays music for Alarm*/
public class SoundPlayer {
public Player player;
public InputStream in= null;
public SoundPlayer() {
try {
in = getClass().getResourceAsStream("/Shuffle A-Tak_2-01.mp3");
player=Manager.createPlayer(in,"audio/mpeg");
player.prefetch();
} catch (Exception e) {
e.printStackTrace();
}
}
public void playsound(String playtype) {
//Play
if (playtype.compareTo(new String("Play")) == 0) {
try {
player.start();
} catch (Exception e) {
System.out.println("xxxxxxxxxxS");
e.printStackTrace();
}
}
//Stop
if (playtype.compareTo("Stop") == 0) {
try {
player.stop();
player.setMediaTime(0);
System.out.println("!!!!!!!!!!!!!!!");
} catch (Exception e) {
System.out.println("!!!!!!!!!!!!!!!***********");
e.printStackTrace();
}
}
}
}
Code:
MIDlet-1: Push,,Push MIDlet-2: Alarm,,Alarm MIDlet-Jar-Size: 412205 MIDlet-Jar-URL: Push_Registry1.jar MIDlet-Name: Push Registry1 Midlet Suite MIDlet-Permissions: javax.microedition.io.PushRegistry MIDlet-Vendor: Midlet Suite Vendor MIDlet-Version: 1.0.0 MicroEdition-Configuration: CLDC-1.1 MicroEdition-Profile: MIDP-2.0 It shows 2 selection Menu, 1.Push 2.Alarm When I select Push I expect it to enter to the Push MIDlet where I can do the Alarm Setting, however 1st it goes back to the place where the application is stored and then only enters the Push MIDlet. This will definately confuse the 1st time user. Is it because the MIDlet vendor is unknown? Am I clear this time? Hoping to get responses. Regards:) |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
||
|
Quote:
Quote:
Thanks R a j - The K e r n e l |
|
Quote:
May be ur problem is two midlets shown at the menu of device and may be u r confuse to choose the right midlet to enter the application. Is it so? thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
Hi,
Jitu read his post,and check the midlet flow,he is selecting the correct midlet, Thanks R a j - The K e r n e l |
|
Join Date: Jul 2008
Posts: 329
Location: Faridabad(Delhi NCR)
ansh.chauhan
Offline
Regular Contributor
|
|
HI raj
But what he want to do it hard to understand. hey buddy what exactly you want tell us Anshu Chauhan J2me Developer |
| ansh.chauhan |
| View Public Profile |
| Find all posts by ansh.chauhan |
|
Im just guessing the problem of original poster. Im not quite able to understand his problem that's why im just asking him.
thanks, jitu_goldie.. KEEP TRYING.. |
| jitu_goldie |
| View Public Profile |
| Find all posts by jitu_goldie |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
||
|
Quote:
I recommend that you should also read the post by scrolling down the page,this is all explained in the post 1 of this thread. Quote:
Thanks R a j - The K e r n e l |
|
Hello Everyone again,
Lets say I stored Push Registry with many other application (Alarm, Calendar, Timer, Sudoku), I cannot show how the screen on phone exaclty looks like, but I will simply "draw" screen transition diagram by words here. 1)Press Application folder : The screen looks like below: Application Push Registy MIDlet Suite Alarm Calendar Timer Sudoku 2) Press Pust Registry MIDlet Suite : The screen looks like below: Push Registy MIDlet Suite Alarm Push 3) Press Push : The screen looks like below, 1st it goes to screen "a" for 2 sec and then only moves to screen "b" a) Application Push Registy MIDlet Suite Alarm Calendar Timer Sudoku b) Set Alarm Set Date and Time 03-Jul-09 15:08:00 My problem is, in No.3 when I press Push i want to go directly to screen "b". I am sorry but, this is the best I can explain:( I hope it is clear this time Regards P.S: Please address me with a "she" |
|
Hello!!
I understand now. You go to the "application menu", where you see a list of MIDlet suites (JAR files). Then you select your suite. Because your suite has two MIDlets, you next see a list of MIDlets in the suite. You select a MIDlet, and you (briefly) see the "application menu" again, before the application starts. Is that correct? To some extent, this is a function of the device. There may be nothing you can do about it. It is important to keep the amount of code in the MIDlet constructor, in static initializers, and in the startApp() method, to a minimum. Reducing the amount of code that is executed during start up may reduce the time. However, you don't appear to have much code. One alternative is to have only one MIDlet. Unfortunately, there is no method to find out if the MIDlet was started from the menu, or by the Alarm. The best you can achieve it to store the registered alarm time in RMS and, at start up, check to see: Code:
if (currentTime >= alarmTime && currentTime < (alarmTime + TIME_WINDOW_SIZE)) {
// assume we were started by the alarm
} else {
// assume we were started from the application menu
}
Otherwise, I think you have to live with the application menu appearing for a moment. You will find that different devices will behave differently. What you are seeing is a quirk of that particular device. Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| MIDlet: Connection bluetooth problem | Wulfric | Bluetooth Technology | 4 | 2009-01-23 15:30 |
| Got Problem with PC Suite | damien77 | PC Suite API and PC Connectivity SDK | 6 | 2006-04-14 05:04 |
| PC Suite Problem Please Help! | dj_raw | PC Suite API and PC Connectivity SDK | 5 | 2006-04-12 07:04 |
| launching MIDlet from another MIDlet on 6310i problem | niko86 | Mobile Java General | 1 | 2002-08-07 10:38 |
| loading ressources using nokia midlet suite | b_varasse | Mobile Java General | 0 | 2002-05-16 12:32 |