0

我正在制作一个应用程序,我想在它第一次运行良好时显示通知,但第二次它没有更新通知中的列表。

public class StatusBar extends Activity {
NotificationManager mn;
static int uniqueId = 1394885;
static ArrayList<String> arrayList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    arrayList = intent.getStringArrayListExtra("nameOfFilesCopied");
    mn = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mn.cancel(uniqueId);

    ahoo();

}

private void ahoo() {
    // TODO Auto-generated method stub
    Intent intent = new Intent("helpsettings.ListOfFilesCopied");
    intent.putStringArrayListExtra("nameOfFilesCopied", arrayList);

    PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
    String body = "List of files that are copied by the connected person";
    String title = "List Of Files Copied";
    // need to craate a notification i.e what the time is
    @SuppressWarnings("deprecation")
    Notification n = new Notification(R.drawable.ic_launcher, body,
            System.currentTimeMillis());
    // add what details we want to our notification
    n.setLatestEventInfo(this, title, body, pi);
    n.defaults = Notification.DEFAULT_LIGHTS;
    mn.notify(uniqueId, n);
    finish();

}

第二次,当我放置 arrayList 并通过挂起的意图我调用下面的类时,挂起的意图发送上一个列表而不是第二个 itme 上的列表公共类 ListOfFilesCopied 扩展 ListActivity {

ArrayList<String> list;
private ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);

    Intent intent = getIntent();

    list = intent.getStringArrayListExtra("nameOfFilesCopied");
    adapter = new MyAdapters(this, R.layout.ahoo, list);
    setListAdapter(adapter);

}

/*
 * (non-Javadoc)
 * 
 * @see android.app.Activity#onBackPressed()
 */
@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    list.clear();
}

/*
 * (non-Javadoc)
 * 
 * @see android.app.Activity#onCreate(android.os.Bundle)
 */

}

4

2 回答 2

0

这是我的通知更新代码......就像一个魅力......

Intent intent = new Intent(DrillListViewActivity.this, DrillListViewActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
/*
 * TaskStackBuilder stackBuilder = TaskStackBuilder
 * .create(DrillListViewActivity.this);
 * 
 * stackBuilder.addNextIntent(intent);
 */
PendingIntent pIntent = PendingIntent.getActivity(
DrillListViewActivity.this, 0, intent, 0);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
    noti = new Notification.Builder(
    DrillListViewActivity.this)
    .setContentTitle(drill.getName())
    .setSmallIcon(R.drawable.applogo)
    .setContentIntent(pIntent)
    .setContentText(
        "Rest time: " + drill.getTimeMin()
        + ":" + drill.getTimeSec()
        + "    Reps: "
        + drill.getReps()
        + "     Sets: "
        + drill.getNumberOfSets())
    .setSubText(" Notes:" + drill.getNotes())
    .getNotification();
} else {
    noti = new Notification.Builder(
    DrillListViewActivity.this)
    .setContentTitle(drill.getName())
    .setSmallIcon(R.drawable.applogo)
    .setContentIntent(pIntent)
    .setContentText(
    LongString)  
    .getNotification();
}

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);

希望对您有所帮助,您可以将其放在 rowclick 中,以便每次选择行时都会更新...

于 2013-09-29T10:58:04.887 回答
0
private void ahoo() {
    // TODO Auto-generated method stub
    Intent intent = new Intent("helpsettings.ListOfFilesCopied");
    intent.putStringArrayListExtra("nameOfFilesCopied", arrayList);


    PendingIntent pi = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
    String body = "List of files that are copied by the connected person";
    String title = "List Of Files Copied";
    // need to craate a notification i.e what the time is
    @SuppressWarnings("deprecation")
    Notification n = new Notification(R.drawable.ic_launcher, body,
            System.currentTimeMillis());
    // add what details we want to our notification
    n.setLatestEventInfo(this, title, body, pi);
    n.defaults = Notification.DEFAULT_LIGHTS;
    mn.notify(uniqueId, n);
    finish();

}
于 2013-09-29T11:15:47.350 回答