相关疑难解决方法(0)

使用Android的getBaseContext,getApplicationContext或使用Activity的"this"的不同规则

我GOOGLE了这个问题很多,已经发现,当使用许多不同的建议getBaseContext,getApplicationContext或活动本身的这个指针.

经常出现并且似乎很有意义的三条规则是 -

  1. 对于上下文活动的长期引用, 只要您的应用程序存在,就应该使用getApplicationContext
  2. 对于生命周期与其活动相关的上下文,应使用自己的活动上下文(this)
  3. 静态存储上下文指针只是非常谨慎(如果可能的话,根本不存在)

假设这些是正确的,getBaseContext有什么用?

我见过许多使用以下方法创建新意图的例子 -

Intent intent = new Intent(getBaseContext(), myClass.class);
Run Code Online (Sandbox Code Playgroud)

与 - 相反 -

Intent intent = new Intent(this, myClass.class);
Run Code Online (Sandbox Code Playgroud)

哪个是正确的或推荐的方法,为什么?

android android-context

42
推荐指数
1
解决办法
2万
查看次数

在Android中收听外发短信或发送框

我正在开发一个应用程序,它将所有传入和传出的短信存储在SD卡的文本文件中.

我能够使用广播接收器收听传入的消息.我发现收听外发短信非常困难.

我知道在某种程度上需要设置发送的盒子或发件箱上的内容观察者,但我不知道该怎么做.

如何才能做到这一点?

sms android

32
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×2

android-context ×1

sms ×1