CN108509234A - 一种基于Android平台处理拍照返回时闪退的方法 - Google Patents
一种基于Android平台处理拍照返回时闪退的方法 Download PDFInfo
- Publication number
- CN108509234A CN108509234A CN201810327089.0A CN201810327089A CN108509234A CN 108509234 A CN108509234 A CN 108509234A CN 201810327089 A CN201810327089 A CN 201810327089A CN 108509234 A CN108509234 A CN 108509234A
- Authority
- CN
- China
- Prior art keywords
- activity
- mainactivity
- sub
- main
- android
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring for program initiating, e.g. using registry, configuration files
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4482—Procedural
- G06F9/4484—Executing subprograms
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
- G06F9/449—Object-oriented method invocation or resolution
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04M—TELEPHONIC COMMUNICATION
- H04M1/00—Substation equipment, e.g. for use by subscribers
- H04M1/72—Mobile telephones; Cordless telephones, i.e. devices for establishing wireless links to base stations without route selection
- H04M1/724—User interfaces specially adapted for cordless or mobile telephones
- H04M1/72403—User interfaces specially adapted for cordless or mobile telephones with means for local support of applications that increase the functionality
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04M—TELEPHONIC COMMUNICATION
- H04M2250/00—Details of telephonic subscriber devices
- H04M2250/52—Details of telephonic subscriber devices including functional features of a camera
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Processing Or Creating Images (AREA)
Abstract
本发明涉及Android平台技术领域,特别涉及一种基于Android平台集成了TabHost的APP其子Activity调用拍照方法后不能返回结果并闪退的解决方法。本发明的方法是在子Activity调用拍照方法时,先在MainActivity中定义静态变量main,并在MainActivity的onCreate方法中初始化main为this,然后在子Activity调用拍照方法中使用MainActivity.main.startActivityForResult方法来启动即可。本发明解决了基于Android平台集成TabHos菜单的APP其子Activity调用拍照方法后不能返回结果并闪退的问题。
Description
技术领域
本发明涉及Android平台技术领域,特别涉及一种基于Android平台解决集成了TabHost菜单的APP其子Activity调用拍照方法后不能返回结果并闪退的方法。
背景技术
在Android平台上集成了TabHost菜单的APP,在其子Activity调用拍照方法时,容易导致接收不到拍照后返回的数据并闪退的问题;为了解决这个问题,需要借助MainActivity来启动拍照功能。
发明内容
本发明解决的技术问题在于提供一种基于Android平台集成了TabHost菜单的APP其子Activity拍照后接收数据的方法;解决了拍照后不能接收到数据并闪退的问题。
本发明解决上述技术问题的技术方案是:
在集成了TabHost菜单的APP其子Activity调用拍照方法时,先在MainActivity中定义静态变量main,并在MainActivity的onCreate方法中初始化main为this,然后在子Activity调用拍照方法中使用MainActivity.main.startActivityForResult方法来启动拍照程序。从而解决了子Activity调用拍照方法后不能返回结果并闪退的问题。
所述的方法具体包括如下步骤:
步骤一、创建一个Android项目,并在MainActivity中集成TabHost菜单栏;
步骤二、在MainActivity中定义类型为MainActivity的静态变量main,并在在onCreate方法中初始化main为this;
步骤三、创建子Activity及带有Button的布局文件;
步骤四、在子Activity中初始化Button,并给其添加onClick方法;
步骤五、在onClick方法中创建跳转到拍照的Intent对象,然后使用使用MainActivity.main.startActivityForResult启动拍照程序;
步骤六、在MainActivity中覆写onActivityResult来接收返回的数据,而不是在子Activity中覆写,接收到数据后传递给子Activity;
步骤七、最后在AndroidManifest.xml中注册Activity及开通拍照所需的相关权限。
本发明的有益效果:当在集成了TabHost菜单的APP其子Activity调用拍照方法时,先在MainActivity中定义静态变量main,并在MainActivity的onCreate方法中初始化main为this,然后在子Activity调用拍照方法中使用MainActivity.main.startActivityForResult方法来启动拍照功能,从而达到接收到拍照返回数据的目的。有效解决解决了子Activity调用拍照方法后不能返回结果并闪退的问题。
附图说明
下面结合附图对本发明进一步说明:
图1为本发明的流程图。
具体实施方式
如图1所示,本发明采用如下步骤:
步骤一、创建一个Android项目,并在MainActivity中集成TabHost菜单栏; 如:
public class MainActivity extends AppCompatActivity implementsTabHost.OnTabChangeListener {
/**底部导航*/
private NoDestroyFragmentTabHost tabHost;
@Override
public void onTabChanged(String tabId) {
TLog.log(TAG, "tabId=====" + tabId);
}
// tab跳转
public void onEventMainThread(ChangeTabEvent event) {
tabHost.setCurrentTab(event.getIndex());
}
}
步骤二、在MainActivity中定义类型为MainActivity的静态变量main,并在在onCreate方法中初始化main为this;如:
public static MainActivity main;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
main = this;
}
步骤三、创建子Activity及带有Button的布局文件;如:
public class ChildActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ child);
}
}
布局文件activity_child.xml
<xml version="1.0" encoding="utf-8">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn_photo" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@mipmap/icon_ photo " />
<TextView
android:id="@+id/tv_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"/>
</LinearLayout>
步骤四、在子Activity中初始化Button,并给其添加onClick方法;如:
public class ChildActivity extends AppCompatActivity {
@InjectView(R.id.btn_photo)
protected Button mBtnPhoto;
@InjectView(R.id.tv_result)
protected TextView mTvResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child);
//注册组件
ButterKnife.inject(this);
//初始化点击事件
initClick();
}
@Override
protected void initClick() {
mBtnPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
省略……
}
});
}
}
步骤五、在onClick方法中创建跳转到拍照的Intent对象,然后使用使用MainActivity.main.startActivityForResult启动拍照程序;如:
Intent intent = new Intent(ChildActivity.this,CaptureActivity.class);
intent.putExtra("from" , Constants.FROM_CHILD);
MainActivity.main.startActivityForResult(intent, Constants.REQUEST_SCAN_QRCODE);
步骤六、在MainActivity中覆写onActivityResult来接收返回的数据,而不是在子Activity中覆写,接收到数据后传递给子Activity;如:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intentdata) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case Constants.REQUEST_SCAN_QRCODE:
processScanResult(data, this);
break;
}
}
}
//处理拍照结果
public void processScanResult(Intent data, Activity activity) {
if (data != null) {
String result = data.getStringExtra("result");
if (TextUtils.isEmpty(result)) {
AppContext.showToast(“unknown error”));
return;
}
Intent intent = new Intent(activity, ChildActivity.class);
intent.putExtra(Constants.SCAN_RESULT, result);
activity.startActivity(intent);
}
}
步骤七、最后在AndroidManifest.xml中注册Activity及开通拍照所需的相关权限。如:
注册activity
<activity
android:name=".ui.MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.ChildActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
权限开通
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera2.full" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />。
Claims (2)
1.一种基于Android平台集成TabHost的APP其子Activity调用拍照方法后不能返回结果并闪退的解决方法,其特征在于:先在MainActivity中定义静态变量main,并在MainActivity的onCreate方法中初始化main为this,然后在子Activity调用拍照方法中使用MainActivity.main.startActivityForResult方法来启动拍照程序,从而解决拍照后闪退的问题。
2.根据权利要求1所述的解决子Activity调用拍照方法后不能返回结果并闪退的方法,其特征在于:所述的方法具体包括如下步骤:
步骤一、创建一个Android项目,并在MainActivity中集成TabHost菜单栏;
步骤二、在MainActivity中定义类型为MainActivity的静态变量main,并在在onCreate方法中初始化main为this;
步骤三、创建子Activity及带有Button的布局文件;
步骤四、在子Activity中初始化Button,并给其添加onClick方法;
步骤五、在onClick方法中创建跳转到拍照的Intent对象,然后使用使用MainActivity.main.startActivityForResult启动拍照程序;
步骤六、在MainActivity中覆写onActivityResult来接收返回的数据,而不是在子Activity中覆写,接收到数据后传递给子Activity;
步骤七、最后在AndroidManifest.xml中注册Activity及开通拍照所需的相关权限。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810327089.0A CN108509234B (zh) | 2018-04-12 | 2018-04-12 | 一种基于Android平台处理拍照返回时闪退的方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810327089.0A CN108509234B (zh) | 2018-04-12 | 2018-04-12 | 一种基于Android平台处理拍照返回时闪退的方法 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108509234A true CN108509234A (zh) | 2018-09-07 |
CN108509234B CN108509234B (zh) | 2021-06-11 |
Family
ID=63382024
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810327089.0A Expired - Fee Related CN108509234B (zh) | 2018-04-12 | 2018-04-12 | 一种基于Android平台处理拍照返回时闪退的方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108509234B (zh) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9344275B2 (en) * | 2012-05-08 | 2016-05-17 | Arm Technologies Israel Ltd. | System, device, and method of secure entry and handling of passwords |
CN105653454A (zh) * | 2015-12-30 | 2016-06-08 | 浙江德景电子科技有限公司 | 一种基于android系统的应用程序异常的处理方法和处理装置 |
CN106445514A (zh) * | 2016-09-13 | 2017-02-22 | Tcl集团股份有限公司 | 一种管理Android平台的Activity实例的方法和装置 |
-
2018
- 2018-04-12 CN CN201810327089.0A patent/CN108509234B/zh not_active Expired - Fee Related
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9344275B2 (en) * | 2012-05-08 | 2016-05-17 | Arm Technologies Israel Ltd. | System, device, and method of secure entry and handling of passwords |
CN105653454A (zh) * | 2015-12-30 | 2016-06-08 | 浙江德景电子科技有限公司 | 一种基于android系统的应用程序异常的处理方法和处理装置 |
CN106445514A (zh) * | 2016-09-13 | 2017-02-22 | Tcl集团股份有限公司 | 一种管理Android平台的Activity实例的方法和装置 |
Non-Patent Citations (2)
Title |
---|
KUT: "《https//my.oschina.net/kut/blog/57335》", 14 May 2012 * |
小熊先生KISCODE: "《http://www.voidcn.com/article/p-epeyfxjj-xa.html》", 28 September 2014 * |
Also Published As
Publication number | Publication date |
---|---|
CN108509234B (zh) | 2021-06-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Cantelon et al. | Node. js in Action | |
Ableson et al. | Android in action | |
KR102159416B1 (ko) | 하이브리드 모바일 애플리케이션을 구축하고 사용하는 시스템 및 방법 | |
US11635974B2 (en) | Providing a different configuration of added functionality for each of the stages of predeployment, deployment, and post deployment using a layer of abstraction | |
CN105760162A (zh) | 混合型app软件的开发方法 | |
Smyth | Firebase essentials-Android edition | |
US11343463B2 (en) | Video script generation, presentation and video recording with flexible overwriting | |
US9268561B1 (en) | Federated services to dynamically switch features in applications | |
WO2014035739A1 (en) | Search extensibility application framework in a hosted search | |
US10198279B2 (en) | Thread synchronization for platform neutrality | |
WO2014012361A1 (zh) | 一种创建外部设备控制界面的方法及装置 | |
US11695843B2 (en) | User advanced media presentations on mobile devices using multiple different social media apps | |
Boyer et al. | Android application development cookbook | |
CN108509234A (zh) | 一种基于Android平台处理拍照返回时闪退的方法 | |
US8166165B1 (en) | Securing event flow in a user interface hierarchy | |
Khanna et al. | Ionic: Hybrid Mobile App Development | |
US20220094747A1 (en) | Connection Management Service | |
Jaygarl et al. | Professional Tizen Application Development | |
Syme et al. | Building mobile web applications | |
Mahmoud | Developing Middleware in Java EE 8: Build robust middleware solutions using the latest technologies and trends | |
King et al. | Advanced BlackBerry Development | |
Anderson | Beginning Flash, Flex, and AIR Development for Mobile Devices | |
Huang | SportMingles sports social network for iOS | |
Alber et al. | Beginning app development with parse and PhoneGap | |
Malgaonkar et al. | A Review and Basic Guidelines on Developing Android Applications |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20210611 |