注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

你想快速掌握安卓编程吗

 
 
 

日志

 
 

返回当前打开应用的例子(一)  

2015-08-30 18:18:51|  分类: B.分享 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

下面是Main视图代码(沉默蜂注解)

#Region Project Attributes
#ApplicationLabel: 二维码扫描
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

'这个演示节目如何运行一个活动的通知,恢复原来的应用程序
'this demo show's how to run an activity from a notification and return to the previous app

Sub Process_Globals

Dim ScanDone As Boolean=True
Dim ATimer As Timer
End Sub

Sub Globals

Dim zx As Zxing_B4A
'B4A Library ZXing v1.6(二维扫描码库)
'http://www.b4x.com/android/forum/threads/zxing-v1-6.43781/

End Sub

Sub Activity_Create(FirstTime As Boolean)

'当第一次触发Activity_Create事件,将启动服务模块
If FirstTime Then
StartService(Scanner)
End If

End Sub

Sub Activity_Resume

'库 Core > 类 Activity > 方法 GetStartingIntent
'GetStartingIntent As IntentWrapper 获得起始目标
'
'(Advanced) Gets the Intent Object that started this Activity.
'This can be used together with SetActivityResult To Return results To 3rd party applications.
'(高级)开始这个活动,获得目标对象.
'这能同时用于 SetActivityResult 来返回第三方应用的结果.


'库 Core > 类 Intent > 方法 HasExtra
'HasExtra ( Name As String ) As Boolean
'
'Tests whether an item with the given key exists.
'测试一个项目是否有给定键的存在.




Log("Activity_Resume 事件")

Dim i As Intent
i=Activity.GetStartingIntent
If i.HasExtra("Notification_Tag") Then

Log("notification")
Log(i.ExtrasToString)
If ScanDone=True Then

If i.GetExtra("Notification_Tag")="scan" Then
'how to update app now?
CallSubDelayed(Me,"ScanNow")
End If
Else
'might need to start a timer cause user might have pressed back key
ATimer.Initialize("ATimer",1000)
ATimer.Enabled=True
End If

Else
Activity.Finish
End If

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ATimer_Tick
ScanDone=True
Activity.Finish
End Sub

'need to handle back key
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode=KeyCodes.KEYCODE_BACK Then
ScanDone=True
Activity.Finish
End If
End Sub

Sub ScanNow
ScanDone=False
zx.BeginScan("zx")
End Sub

'扫描结束后触发此事件
Sub zx_result(atype As String,Values As String)
'copy to clipboard
If ATimer.IsInitialized Then
ATimer.Enabled=False
End If
Log("result")
ScanDone=True
Dim cb As BClipboard
cb.setText(Values)
Activity.Finish
End Sub

  评论这张
 
阅读(158)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017