I have problem with some basic Android knowledge. My problem is I don't know how to fill in a value from ArrayList. Currently I have 2 applications, one application sending an information through intent, and another application receiving the information.
In the first application, it will receive some information for specific printer's error. All the information I have to show in other application as a notification. The notification (the second application) I have implemented it, it is can show the notification. The notification is carried by a String type and with intent it can sent to second apps.
I have one method called updateUI(). Because I have to keep updated the Interface and the information for my first application, I'm using a service. So, updateUI() in every certain seconds will be called.
I have ArrayList, called error. This list will collect all the information:
ArrayList<String> error;
I have declared the notification in first application:
String notification;
Right now I want to fill this String from ArrayList. Before doing that I have declared temporary String called temp. This string will avoid the same notification that will be sent to notification app when updateUI() has been called again.
for (int i = 0; i < error.size(); i++) {
if (error.get(i) != null) {
notification= error.get(i);
if (notification.equals(temp)) {
notification = null;
}
else
{
temp = notification;
}
}
}
This is how I sent the notification:
Intent broadCastIntent = new Intent("SendMessage");
broadCastIntent.putExtra("ERROR", notification);
sendBroadcast(broadCastIntent);
If the arrayList contains one element, it works fine. But if there are 2 events happen, so the error array have 2 elements, It will only show the second element.I want to sent the first element as a notification followed by second elements.
Example:
in error has 2 elements
error = {"Ink Black is empty","Ink Magenta is Empty",null,null};
when we go to for statement
First index:
for (int i = 0; i < error.size(); i++) {
if (error.get(0) != null) { ---------> Error.get[0] = "Ink Black..."
notification= error.get(i); ---> notification = "Ink Black..."
if (notification.equals(temp)) {
notification = null;
}
else
{
temp = notification;---> temp= "Ink Black..."
}
}
}
Second index:
for (int i = 0; i < error.size(); i++) {
if (error.get(1) != null) { --------> Error.get[1] = "Ink Magenta..."
notification= error.get(1);----> notification = "Ink Magenta..."
if (notification.equals(temp)) {---> "(Ink Magenta...".equals("Ink Black...")
notification = null;
}
else
{
temp = notification; ----->temp= "Ink Magenta..."
}
}
}
After went to for statement the notification only contained "Ink Magenta..". Because of that the notification apps only show :Ink Magenta..." Anybody knows how to distinguish elements of Arraylist so I can sent it one by one?
I have tried without for statement, but I have got null pointer if there is only one element inside the arraylist.
if (!error.get(0).isEmpty())
{
if (error.get(0).equals(temp))
{
if (!error.get(1).isEmpty() && !error.get(1).equals(tempA))
{
notification = error.get(1);
tempA = error.get(1);
}
else
{
notification= null;
}
}
else
{
notification= error.get(0);
temp = error.get(0);
}
}
else
{
notification= null;
}
Anybody knows how to solve my problem? So that I can use other elements