Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Not getting my value read....

Hi guys, I am going to try and explain this to the best of my ability so please be fragile towards me as I am new to development.

 

I am going to attach two classes of code snippet... What I want is for the backgroundWorker to read the value (number of outgoing Calls) from LogReader. If you do browse through the code snippet and happen to see where the error is please let me know urgently. Thanx Alot

 

BackgroundWorker:

public final class BackgroundWorker extends MainScreen
{
private static LabelField label_normalcalls;


public BackgroundWorker()

{
// super();

setTitle("NetTrax ");
label_normalcalls= new LabelField("Number Of Outgoing Calls: 0",LabelField.FOCUSABLE);
add(label_normalcalls);

}

public boolean onClose()
{
UiApplication.getUiApplication().requestBackground();
return true;
}

public void LogReader(String normalCalls){


freebbalerts.LogReader lr = new freebbalerts.LogReader();

normalCalls = lr. findNormalCalls(PhoneLogs.FOLDER_NORMAL_CALLS);
{

synchronized (Application.getEventLock())
{

label_normalcalls.setText(" number of outgoing call:" +normalCalls);
}
}
}

}

 

LogReader:

public class LogReader extends UiApplication implements PhoneLogListener{
public PhoneLogs _logs;
public String _normalcalls;

static public void main(String[] args) {
LogReader app = new LogReader();
app.enterEventDispatcher();
PhoneLogs.addListener(app);
}

public LogReader() {
_logs = PhoneLogs.getInstance();
_normalcalls = findNormalCalls(PhoneLogs.FOLDER_NORMAL_CALLS);
pushScreen(new LogReaderScreen(_normalcalls));
}

public String findNormalCalls(long folder) {
int totalCalls = this._logs.numberOfCalls(folder);
int normalCalls = 0;
for(int i=0;i<totalCalls;i++){
PhoneCallLog cl = (PhoneCallLog) _logs.callAt(i,folder);
if(cl.getType() == PhoneCallLog.TYPE_PLACED_CALL){
normalCalls++;
}
}
return Integer.toString(normalCalls);
}

public void callLogAdded(CallLog cl){
System.out.println("added");


_logs = PhoneLogs.getInstance();
_normalcalls = findNormalCalls(PhoneLogs.FOLDER_NORMAL_CALLS);
pushScreen(new LogReaderScreen(_normalcalls));
}

public void callLogRemoved(CallLog cl){
System.out.println("removed");

}
public void callLogUpdated(CallLog cl, CallLog Oldcl){
System.out.println("updated");
}
public void reset(){
_logs = PhoneLogs.getInstance();
}
}

final class LogReaderScreen extends MainScreen{

public LogReaderScreen(String normalCalls){

}
public void monitorLog(String normalCalls){

}
}


Thank you guys

Developer
Posts: 16,676
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Not getting my value read....

app.enterEventDispatcher(); does not return, so your listener is never added
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Not getting my value read....

Thank you for the fast reply but if I may ask of you to provide me with a short code snippet of how to fix this please? :smileyhappy:

Developer
Posts: 16,676
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Not getting my value read....

[ Edited ]

put PhoneLogs.addListener(app); into the constructor of your app or before the enterEventDispatcher.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Not getting my value read....

Hi there 

Thank you for your help but unfortunately this did not solve my problem. If you have any other advice, feel free to post it :smileysad:

 

Kind regards