我也尝试使用 ,ApplicationContext但由于某种原因它仍然泄漏。
在 Android 版 AdMob (SDK 7.0) 上的 AdActivity 泄漏中找到了有关此问题的类似帖子,但没有答案。
还尝试在 onDestroy() 中将 adlistener 和广告设置为 null 但没有任何运气并且仍然泄漏活动。
我的代码在 onCreate() 中调用
private void refreshInterstitial(){
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("AD_ID");
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("877BCC97E130A0DC62B2E5770D854496").build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
mInterstitialAd.show();
}
@Override
public void onAdClosed() {
}
});
}
Run Code Online (Sandbox Code Playgroud)
Leakcanary 泄漏跟踪
????
? GC Root: Global variable in native code
?
?? mx instance
? Leaking: UNKNOWN
? ? mx.a
? ~
?? com.google.android.gms.ads.internal.webview.w instance …Run Code Online (Sandbox Code Playgroud) 我应该在 onCreateView、onViewCreated 还是 onActivityCreated 中初始化我的回收视图?
这三个之间有什么区别,我搜索了解释,但有些人说使用 onCreateView ,有些人说使用 onViewCreated 或 onActivityCreated 并且只使用 onCreateView 来膨胀布局?
这是我的代码
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_tab1, container, false);
recyclerViewSongs = rootView.findViewById(R.id.recyclerViewSongs);
initRecyclerView();
Log.e(TAG, "onCreateView called!");
return rootView;
}
private void initRecyclerView() {
Main.musicList = Main.songs.songs;
// Connects the song list to an adapter
// (Creates several Layouts from the song list)
allSongsAdapter = new AllSongsAdapter(getContext(), Main.musicList);
final LinearLayoutManager linearLayoutManager …Run Code Online (Sandbox Code Playgroud) java android android-fragments android-recyclerview fragment-oncreateview
我正在尝试更新音频文件的流派标签。
码
final Uri genreUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;
String currentGenreName = MediaStore.Audio.Genres.NAME;
ContentValues values2 = new ContentValues();
values2.put(currentGenreName, genre);
String whereGenre = MediaStore.Audio.Genres._ID + "=?";
String[] whereVal2 = {Long.toString(genreID)};
resolver.update(genreUri, values2, whereGenre, whereVal2);
Run Code Online (Sandbox Code Playgroud)
我没有收到任何错误,但是MediaStore流派表中的流派没有更新。
其他标签(如标题,艺术家,专辑和艺术品)已更新,仅流派无效。
我也找不到有关更新音频文件中流派名称的任何信息,我只能通过上面的标签来做到这一点。
编辑
我用于编辑标题,艺术家,专辑名称和年份标签的代码,效果很好,所以我认为我必须对类型名称进行相同的操作,因为我具有类型ID。
final Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
ContentResolver resolver = c.getContentResolver();
String currentTitle = MediaStore.Audio.Media.TITLE;
String currentArtist = MediaStore.Audio.Media.ARTIST;
String currentAlbumID = MediaStore.Audio.Media.ALBUM_ID;
String currentAlbum = MediaStore.Audio.Media.ALBUM;
String currentGenreID = MediaStore.Audio.Genres._ID;
String currentGenreName = MediaStore.Audio.Genres.NAME;
String currentAlbumData = MediaStore.Audio.Media.DATA;
String currentYear …Run Code Online (Sandbox Code Playgroud) 更新Android Studio之后,我在viewpager的xml中收到此错误。奇怪的是,它可以正常工作,并且项目构建没有任何问题。
'@ string / appbar_scrolling_view_behavior'是未解决的类的原因是 什么?
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
Run Code Online (Sandbox Code Playgroud)
我的viewpager在CoordinatorLayout内部。
我的字体 xml 中出现以下错误。
安东.xml
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Anton"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>
Run Code Online (Sandbox Code Playgroud)
在这一行它说无法解析符号:
error: resource array/com_google_android_gms_fonts_certs
Run Code Online (Sandbox Code Playgroud)
在它工作之前,但我将我的项目从我的 MacBook 复制到 Windows 电脑,由于某种原因,我现在收到此错误。
我尝试删除字体,甚至尝试了另一种字体,但仍然遇到相同的错误。
如何在不嵌套视图组的情况下对约束布局中的视图进行分组?
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/color1">
<ImageView
android:id="@+id/mAlbumArtLarge"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY"
android:src="@drawable/image1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<android.support.constraint.ConstraintLayout
android:id="@+id/mBottomSheet"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#20000000"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/mAlbumIvBottom"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这就是我现在正在做的事情来创建一个容器mBottomSheet,我可以在其中对视图进行分组并设置背景,但是我constraintlayout为此使用了另一个视图组,这是不推荐的,因为约束布局的点太具有平面视图层次结构。
那么我怎样才能实现同样的事情,但不使用另一个视图组作为容器呢?
编辑
例子:
我对 MediaControllerCompat 和 MediaSessionCompat 的导入
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
private MediaSessionCompat mMediaSessionCompat;
private MediaControllerCompat.TransportControls mTransportControls;
Run Code Online (Sandbox Code Playgroud)
我最近将我的项目迁移到 Android X,但这些导入在迁移时没有改变,而是将其添加到我的 gradle 依赖项中。
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Run Code Online (Sandbox Code Playgroud)
现在我想知道为什么他们没有更改为 Android X,我搜索了MediaControllerCompat 和 MediaSessionCompat的 android x 依赖项,但我找不到它们。
由于某种原因 MediaStore 列MediaStore.Audio.Media.DURATION现在仅在 API29 上可用,并且 Android Studio 现在显示一条警告,表明它需要 Android Q。
我不知道为什么,因为我已经使用这个专栏很长时间了。
即使在文档中也写着“Added in API29”。
https://developer.android.com/reference/android/provider/MediaStore.MediaColumns#DURATION
由于Android Q (API29)中的Android 隐私更改,无法将歌曲添加到播放列表,并且在添加曲目时会抛出此错误消息。
java.lang.SecurityException: com.mp3player.mp3player has no access to content://media/external_primary/audio/media/117
Run Code Online (Sandbox Code Playgroud)
我知道我们可以将其捕获为一个RecoverableSecurityException并单独授予每个文件的权限。
但这真的很麻烦,我想知道是否还有其他方法。
我已经找到了来自用户 @Theo的帖子,其中有同样的问题,但没有任何答案。
将歌曲添加到播放列表的代码
public void addToPlayList(Context c, long songID, long playListID, String playlistName) {
Uri playListUri = MediaStore.Audio.Playlists.Members.getContentUri("external", playListID);
String[] columns = {
MediaStore.Audio.Playlists.Members.AUDIO_ID,
MediaStore.Audio.Playlists.Members.PLAY_ORDER,
};
ContentResolver resolver = c.getContentResolver();
Cursor cursor = resolver.query(playListUri, columns, null, null, null);
int playOrder = 0;
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
playOrder = cursor.getInt(0) + 1;
}
cursor.close();
ContentValues …Run Code Online (Sandbox Code Playgroud) 我制作了一个带有媒体服务的Mediaplayer应用,该服务控制着我的Mediaplayer对象。
一切正常,但我的logcat每秒都被此消息淹没。
此消息是什么意思?
Logcat(资讯)
W/audio_hw_generic: Not supplying enough data to HAL, expected position
7310473 , only wrote 7310160
W/audio_hw_generic: Not supplying enough data to HAL, expected position
7326138 , only wrote 7326000
W/audio_hw_generic: Not supplying enough data to HAL, expected position
7326108 , only wrote 7326000
W/audio_hw_generic: Not supplying enough data to HAL, expected position
7328176 , only wrote 7326720
W/audio_hw_generic: Not supplying enough data to HAL, expected position
7330512 , only wrote 7330320
W/audio_hw_generic: Not supplying enough data to …Run Code Online (Sandbox Code Playgroud) 这是我的menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/search_icon"
android:title="@string/action_search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
<item
android:id="@+id/action_favorite"
android:icon="@drawable/favorite_icon"
android:title="@string/action_favorite"
app:showAsAction="always" />
<item
android:id="@+id/themes"
android:title="@string/overflow_menu_item"
app:showAsAction="never">
<menu>
<item
android:id="@+id/background1"
android:title="Red-PinkGradient"
/>
<item
android:id="@+id/background2"
android:title="Red-Gradient"
/>
<item
android:id="@+id/background3"
android:title="Green-Gradient"
/>
<item
android:id="@+id/background4"
android:title="Black-GreyGradient"
/>
</menu>
</item>
<item
android:title="@string/overflow_menu_item2"
android:id="@+id/settings"
/>
Run Code Online (Sandbox Code Playgroud)
这是我的styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="actionOverflowButtonStyle">@style/overFlow</item>
<item name="searchViewStyle">@style/CustomSearchViewStyle</item>
</style>
<style name="overFlow" parent="@style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">@drawable/ic_overflow_icon</item>
</style>
<style name="CustomSearchViewStyle" parent="Widget.AppCompat.SearchView">
<item name="queryBackground">@color/white</item>
<item name="searchIcon">@drawable/search_icon</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如何更改搜索视图的图标颜色?我试图将我的项目中的图标设置为可绘制对象,这是一个白色的搜索图标,但我保持黑色。 …
android ×11
java ×8
xml ×3
mediastore ×2
androidx ×1
font-family ×1
fonts ×1
interstitial ×1
logcat ×1
memory-leaks ×1
menuitem ×1
uri ×1