Android 从其他班级开始活动
谷歌地图显示在这里,我也想发出通知,当我点击它,通知应该带我到主要活动,即谷歌地图,但通知没有发出。这里有2个类和清单文件Android 从其他班级开始活动,android,Android,谷歌地图显示在这里,我也想发出通知,当我点击它,通知应该带我到主要活动,即谷歌地图,但通知没有发出。这里有2个类和清单文件 public class MainActivity extends FragmentActivity{ protected GoogleMap gMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
public class MainActivity extends FragmentActivity{
protected GoogleMap gMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (gMap == null) {
Toast.makeText(this, "Google Maps not available",
Toast.LENGTH_LONG).show();
gMap.setMyLocationEnabled(true);
}
}
通知班级
public class Notify extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.jollyr)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentTitle("Flood Warning")
.setContentText("You are in Danger Zone");
// Sets an ID for the notification
int notId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(notId, mBuilder.build());
Intent i=new Intent(this,MainActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
i,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
}
}
清单文件
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.map.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.map.Notify"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.map.Notify" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="Package+.v2.API_KEY"
android:value="Key here" />
</application>
</manifest>
Notify活动导航到哪里?您没有导航到Notify
活动。您的通知将显示在那里。main活动中没有单击侦听器。所以你的通知没有显示。所以我必须在MainActivity中创建一个单击侦听器?这将打开通知类!是类似于单击地图显示通知否否,在显示地图时会显示通知。但当单击通知时,地图仅显示,不再显示通知。