首页 \ 问答 \ Android如果已注册启动服务活动,则启动注册活动(Android If registered launch service activity else launch registration activity)

Android如果已注册启动服务活动,则启动注册活动(Android If registered launch service activity else launch registration activity)

我想知道如果用户已经注册了如何让我的应用程序启动服务活动?它没有登录活动而是注册活动。 因此,应用程序将从注册活动开始,注册后将进入服务活动。 当用户关闭应用程序时,如何使其从服务活动再次启动而不是从注册活动启动?

如何让它识别它是否已注册进入服务活动,如果它没有启动注册活动(登录数据将存储在共享偏好中我不知道如何做到这一点虽然如果它断开连接它将不得不重新连接)

我会感激任何答复,谢谢。


I was wondering how to make my app launch the service activity if the user is already registered?, it wont have login activity but registration activity. So the app will start with the registration activity, after registration it will go to the service activity. When user closes the app, how to make it launch again from the service activity and not from registration activity?

How to make it recognize if it is registered go to the service activity and if it is not launch the registration activity(login data will be stored in sharedpreferences I dont know any other way how to do it though in case it disconnects it will have to reconnect again)

I will appreciate any answer, Thanks.


原文:https://stackoverflow.com/questions/29584538
更新时间:2023-04-18 17:04

最满意答案

函数重载的事实并不真正相关。 这里真正的问题是函数指针和成员函数指针之间的区别。 我将在不重载的情况下运行一些示例。

解决方案:删除static ,以便将它们定义为成员函数。 或者用' ns::ClassA::*ClassA_foo1替换ns::ClassA::*ClassA_foo1 *ClassA_foo1 。 我想你想要后者。 (但我实际上建议你使用typedef ,正如其他人已经建议的那样)。

考虑这两个:

namespace ns {
struct ClassA
{
    static ClassA foo(long);
};
}

namespace ns {
struct ClassA
{
    ClassA foo(long);
};
}

在前一种情况下,foo是static ,因此是一个典型的函数,可以存储在函数指针中:

ns::ClassA (ClassA_foo1)(long) = &ns::ClassA::foo;

如果你删除static ,那么它不再是一个函数,它是一个成员函数。 指向成员函数的指针与指向函数的指针不同,它们必须使用一个对象来执行,该对象将是调用该方法的对象。

函数指针的类型包括返回值的类型和参数的类型。 但是指向成员函数的指针类型还必须包含this对象的类型 - 您不希望能够在BankAccount类型的对象上从Circle运行方法。

声明指向函数的指针:

 ReturnType (*variable_name) (PARAM1, PARAM2)

声明指向成员函数的指针:

 ReturnType (ThisObjectType::*variable_name) (PARAM1, PARAM2)

最后一行是有趣的。 乍一看,您可能认为R (A::*v) (P1,P2)声明了一个正常的函数指针,并将结果变量v放入A范围。 但事实并非如此。 相反,它定义了一个指向成员的指针函数,该函数对类型A对象进行操作。


The fact that the function is overloaded is not really relevant. The real issue here is the difference between a function-pointer and a member-function-pointer. I'll run through some examples without overloading.

Solution: Either remove the static, in order to define them as member-functions. Or else replace ns::ClassA::*ClassA_foo1 with *ClassA_foo1. I think you want the latter. (But I actually recommend you use typedef, as others have already suggested).

Consider these two:

namespace ns {
struct ClassA
{
    static ClassA foo(long);
};
}

and

namespace ns {
struct ClassA
{
    ClassA foo(long);
};
}

In the former case, foo is static and is therefore a typical function, and can be stored in a function-pointer:

ns::ClassA (ClassA_foo1)(long) = &ns::ClassA::foo;

If you remove the static, then it is not a function any more, it's a member function. And pointers-to-member-functions are different from pointers-to-functions, they must be executed with an object that will be the this object on which the method is called.

The type of a function pointer includes the type of the return value and the type of the parameters. But the type of a pointer-to-member-function must also include the type of the this object - you wouldn't expect to be able to run a method from a Circle on an object of type BankAccount.

Declaring a pointer-to-function:

 ReturnType (*variable_name) (PARAM1, PARAM2)

Declaring a pointer-to-member-function:

 ReturnType (ThisObjectType::*variable_name) (PARAM1, PARAM2)

This last line is the interesting one. At first glance, you might think that R (A::*v) (P1,P2) declares a normal function-pointer and places the resulting variable v into the A scope. But it does not. Instead it defines a pointer-to-member-function which operates on objects of type A.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。