2011-04-24 82 views

回答

1

查看有关创建状态栏通知的文档。这绝对涵盖了使用Intent和PendingIntent的通知的起始和活动。

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

至于如果该活动已经在运行,完成它和新鲜的开始吧...我不知道,可以轻松完成,这取决于你真正想要的。您可以做一些与清单中的发射方式活动参数:

http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

,然后让活动响应(与onNewIntent()最有可能的)和编程“复位”本身。可能与这样的事情:

Android restart my activity

1

你的意思是重新开始活动A?虽然最常见的方法就是重新启动一个新的意图与你的同一班,我认为它使用的方式太内存。我宁愿创建一个“init”方法,该方法应该从onCreate中调用,并且当你想重新启动你的活动时。例如:

public void onCreate(Bundle si){ 
    // Call super and set your layout... 
    init(); 
} 

/** 
* This method should be called whenever you want to restart your activity. The 
* biggest advantage is you already have your layout (setContentView() method) 
*/ 
private void relaunchActivityA(){ 
    // Clean or save anything you need to clean or save 
    init(); 
} 

private void init(){ 
    // Init your variables, threads, and so on 
} 

如果你写了“完成那和重新开始活动A”代替“活动B”,然后之后你startActivity() - 开活动A-叫“完成”。例如:

// This is inside Activity A 
Intent i = new Intent(this, ActivityB.class); 
startActivity(); 
finish(); // This will be called right after 'Activity B' finishes 
+0

它可以通过使用活动B来完成,但我从通知开始活动A. – Android 2011-04-24 09:00:43