我将值传递给此服务
MyService.user = new ChatUser(task.getResult().getUser().getUid(),task.getResult().getUser().getDisplayName(), task.getResult().getUser().getEmail(), password, true, "");
Intent intent = new Intent(Login.this, MyService.class);
startService(intent);
当销毁应用程序时,服务继续以标志START_REDELIVER_INTENT
运行,但我传递给它的用户变为空
如何防止值返回null
答案 0 :(得分:1)
您实例化错误的服务。正确的步骤是:
创建一个intent并为其添加所需的值,如下所示:
Try
outFile = My.Computer.FileSystem.OpenTextFileWriter(myPath, True, System.Text.Encoding.ASCII)
outFile.WriteLine(macroText)
outFile.Close()
Catch ex As Exception
在您的服务中:
Intent intent = new Intent(this, Service.class);
intent.putExtra("uid_key", task
.getResult()
.getUser()
.getUid());
intent.putExtra("display_name_key", task
.getResult()
.getUser()
.getDisplayName()));
startService(intent);