主要活动
public static void restartFirstActivity()
{
Intent i = getApplicationContext().getPackageManager()
.getLaunchIntentForPackage(getApplicationContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(i);
}
BroadcastReceiver类
import com.example.aa.MainActivity;
public class NetworkChange extends BroadcastReceiver{
MainActivity ma = new MainActivity();
ma.restartFirstActivity();
}
我在MainActivity的静态中出错。
答案 0 :(得分:1)
答案:
import com.example.aa.MainActivity;
public class NetworkChange extends BroadcastReceiver{
Intent a = new Intent(context, MainActivity.class);
a.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(a);
}