问题描述
我有两个根据逻辑开始的活动。角色检查和活动发现成功!一切正常!当角色更改时,问题将在下一刻开始!单击通知后,如何打开上次打开的 MainActivity->用户或 MainActivity->管理员?重要条件!活动不得再次创建!并且在后台有一个应用程序然后创建一个新活动!
public static class MainActivity extends AppCompatActivity {
public static class User extends MainActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this,"User role",Toast.LENGTH_LONG).show();
}
}
public static class Admin extends MainActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this,"Admin role",Toast.LENGTH_LONG).show();
}
}
}
在打开应用程序并选择了上一个保存的角色后,此处的逻辑起作用了!然后根据角色开始活动!
public static class AuthActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Here the future role is determined (logic is not important)
boolean isAdmin = new Random().nextInt() % 2 == 0;
// Run activity to front
startActivity(new Intent(this,isAdmin ? MainActivity.Admin.class : MainActivity.User.class));
finish();
// MainActivity is running...
}
}
最后。
public static class FirebaseService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
// Attention!
// Attention!
// Attention!
// If the activity was started !!! It should ONLY update onNewIntent (Intent intent) !!! Otherwise they must be re-created!
Intent intent = new Intent(getApplicationContext(),null /* What is there to write in this script? */);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),null,PendingIntent.FLAG_UPDATE_CURRENT);
// Standard show notification (skip)!
super.onMessageReceived(remoteMessage);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)